source: trunk/Packages/CoolAudio/Playlist.pas

Last change on this file was 75, checked in by chronos, 8 months ago
  • Modified: Removed U prefix from CoolAudio package unit names.
File size: 1.7 KB
Line 
1unit Playlist;
2
3interface
4
5uses
6 Classes, SysUtils, Generics.Collections, AudioSystem;
7
8type
9 TPlaylistItem = class
10 FileName: string;
11 end;
12
13 { TPlayList }
14
15 TPlayList = class(TComponent)
16 private
17 FRandomOrder: Boolean;
18 FRepeatInfinitely: Boolean;
19 public
20 CurrentIndex: Integer;
21 procedure AddFile(FileName: string);
22 procedure Shuffle;
23 procedure Play;
24 procedure PlayNext;
25 procedure PlayPrevious;
26 constructor Create(AOwner: TComponent); override;
27 destructor Destroy; override;
28 published
29 Player: TMediaPlayer;
30 Items: TObjectList<TPlaylistItem>;
31 property RandomOrder: Boolean read FRandomOrder write FRandomOrder;
32 property RepeatInfinitely: Boolean read FRepeatInfinitely
33 write FRepeatInfinitely;
34 end;
35
36
37implementation
38
39{ TPlayList }
40
41procedure TPlayList.AddFile(FileName: string);
42var
43 NewItem: TPlaylistItem;
44begin
45 NewItem := TPlaylistItem.Create;
46 NewItem.FileName := FileName;
47 Items.Add(NewItem);
48end;
49
50procedure TPlayList.Shuffle;
51begin
52end;
53
54procedure TPlayList.Play;
55begin
56 Player.FileName := TPlaylistItem(Items[CurrentIndex]).FileName;
57 Player.Play;
58end;
59
60procedure TPlayList.PlayNext;
61begin
62 Inc(CurrentIndex);
63 if CurrentIndex >= Items.Count then begin
64 CurrentIndex := 0;
65 if RandomOrder then Shuffle;
66 if not RepeatInfinitely then Player.Stop;
67 end;
68 Play;
69end;
70
71procedure TPlayList.PlayPrevious;
72begin
73 Dec(CurrentIndex);
74 if CurrentIndex < 0 then begin
75 CurrentIndex := Items.Count - 1;
76 end;
77 Play;
78end;
79
80constructor TPlayList.Create(AOwner: TComponent);
81begin
82 inherited;
83 Items := TObjectList<TPlaylistItem>.Create;
84end;
85
86destructor TPlayList.Destroy;
87begin
88 FreeAndNil(Items);
89 inherited;
90end;
91
92end.
93
Note: See TracBrowser for help on using the repository browser.