1 | unit Playlist;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Generics.Collections, AudioSystem;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
37 | implementation
|
---|
38 |
|
---|
39 | { TPlayList }
|
---|
40 |
|
---|
41 | procedure TPlayList.AddFile(FileName: string);
|
---|
42 | var
|
---|
43 | NewItem: TPlaylistItem;
|
---|
44 | begin
|
---|
45 | NewItem := TPlaylistItem.Create;
|
---|
46 | NewItem.FileName := FileName;
|
---|
47 | Items.Add(NewItem);
|
---|
48 | end;
|
---|
49 |
|
---|
50 | procedure TPlayList.Shuffle;
|
---|
51 | begin
|
---|
52 | end;
|
---|
53 |
|
---|
54 | procedure TPlayList.Play;
|
---|
55 | begin
|
---|
56 | Player.FileName := TPlaylistItem(Items[CurrentIndex]).FileName;
|
---|
57 | Player.Play;
|
---|
58 | end;
|
---|
59 |
|
---|
60 | procedure TPlayList.PlayNext;
|
---|
61 | begin
|
---|
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;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | procedure TPlayList.PlayPrevious;
|
---|
72 | begin
|
---|
73 | Dec(CurrentIndex);
|
---|
74 | if CurrentIndex < 0 then begin
|
---|
75 | CurrentIndex := Items.Count - 1;
|
---|
76 | end;
|
---|
77 | Play;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | constructor TPlayList.Create(AOwner: TComponent);
|
---|
81 | begin
|
---|
82 | inherited;
|
---|
83 | Items := TObjectList<TPlaylistItem>.Create;
|
---|
84 | end;
|
---|
85 |
|
---|
86 | destructor TPlayList.Destroy;
|
---|
87 | begin
|
---|
88 | FreeAndNil(Items);
|
---|
89 | inherited;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | end.
|
---|
93 |
|
---|