Changeset 353 for CoolAudio/Demo/UFormMain.pas
- Timestamp:
- Apr 23, 2012, 2:57:12 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
CoolAudio/Demo/UFormMain.pas
r352 r353 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, ExtCtrls, ActnList, UAudioSystem, UAudioSystemFMOD,10 U AudioSystemMPlayer, UCoolAudio, UPlaylist;9 ComCtrls, ExtCtrls, ActnList, UAudioSystem, 10 UCoolAudio, UPlaylist; 11 11 12 12 type … … 32 32 ComboBoxBackend: TComboBox; 33 33 Label1: TLabel; 34 Label2: TLabel; 34 35 LabelPosition: TLabel; 36 MediaPlayer: TMediaPlayer; 35 37 OpenDialog1: TOpenDialog; 38 PlayList: TPlayList; 36 39 TimerPlayback: TTimer; 37 TrackBar1: TTrackBar; 40 TrackBarPosition: TTrackBar; 41 TrackBarVolume: TTrackBar; 38 42 procedure AOpenExecute(Sender: TObject); 39 43 procedure APauseExecute(Sender: TObject); … … 46 50 procedure FormCreate(Sender: TObject); 47 51 procedure FormDestroy(Sender: TObject); 52 procedure FormShow(Sender: TObject); 48 53 procedure TimerPlaybackTimer(Sender: TObject); 49 procedure TrackBar1Change(Sender: TObject); 54 procedure TrackBarPositionChange(Sender: TObject); 55 procedure TrackBarVolumeChange(Sender: TObject); 50 56 private 51 { private declarations }52 57 public 53 AudioSystem: TAudioSystem;54 Player: TPlayer;55 Playlist: TPlaylist;56 58 procedure UpdateInterface; 57 59 end; … … 74 76 procedure TFormMain.FormCreate(Sender: TObject); 75 77 begin 76 Play list := TPlaylist.Create(nil);78 PlayList := TPlayList.Create(nil); 77 79 AudioSystemManager.FillStringList(ComboBoxBackend.Items); 78 80 if ComboBoxBackend.Items.Count > 0 then … … 83 85 procedure TFormMain.FormDestroy(Sender: TObject); 84 86 begin 85 FreeAndNil(Player); 86 FreeAndNil(AudioSystem); 87 FreeAndNil(Playlist); 87 FreeAndNil(PlayList); 88 end; 89 90 procedure TFormMain.FormShow(Sender: TObject); 91 begin 92 UpdateInterface; 88 93 end; 89 94 90 95 procedure TFormMain.TimerPlaybackTimer(Sender: TObject); 91 96 begin 92 if Assigned(Player) and Player.Playing then begin 93 TrackBar1.OnChange := nil; 94 TrackBar1.Position := Trunc(Player.Position / Player.Length * TrackBar1.Max); 97 if Assigned(MediaPlayer) and MediaPlayer.Playing then begin 98 TrackBarPosition.OnChange := nil; 99 TrackBarPosition.Position := Trunc(MediaPlayer.Position / MediaPlayer.Length * TrackBarPosition.Max); 100 TrackBarVolume.OnChange := nil; 101 TrackBarVolume.Position := Trunc(MediaPlayer.Volume * TrackBarVolume.Max); 95 102 Application.ProcessMessages; 96 TrackBar1.OnChange := TrackBar1Change; 97 LabelPosition.Caption := 'Position: ' + TimeToStr(Player.Position) + ' / ' + TimeToStr(Player.Length); 103 TrackBarPosition.OnChange := TrackBarPositionChange(); 104 TrackBarVolume.OnChange := TrackBarVolumeChange(); 105 LabelPosition.Caption := 'Position: ' + TimeToStr(MediaPlayer.Position) + ' / ' + TimeToStr(MediaPlayer.Length); 98 106 end; 99 107 end; 100 108 101 procedure TFormMain.TrackBar 1Change(Sender: TObject);109 procedure TFormMain.TrackBarPositionChange(Sender: TObject); 102 110 begin 103 Player.Position := TrackBar1.Position / TrackBar1.Max * Player.Length; 111 MediaPlayer.Position := TrackBarPosition.Position / TrackBarPosition.Max * MediaPlayer.Length; 112 end; 113 114 procedure TFormMain.TrackBarVolumeChange(Sender: TObject); 115 begin 116 MediaPlayer.Volume := TrackBarVolume.Position / TrackBarVolume.Max; 104 117 end; 105 118 106 119 procedure TFormMain.UpdateInterface; 107 120 begin 121 APlay.Enabled := not MediaPlayer.Playing; 122 APause.Enabled := MediaPlayer.Playing; 123 AStop.Enabled := MediaPlayer.Playing; 108 124 Caption := ApplicationTitle; 109 if Assigned( Player) then Caption :=Player.FileName + ' - ' + Caption;125 if Assigned(MediaPlayer) then Caption := MediaPlayer.FileName + ' - ' + Caption; 110 126 end; 111 127 112 128 procedure TFormMain.ComboBoxBackendChange(Sender: TObject); 113 129 begin 114 FreeAndNil(Player);115 FreeAndNil(AudioSystem);116 130 if ComboBoxBackend.ItemIndex <> - 1 then begin 117 131 with TAudioSystemManagerItem(ComboBoxBackend.Items.Objects[ComboBoxBackend.ItemIndex]) do begin 118 AudioSystem := SystemClass.Create(nil); 119 Player := PlayerClass.Create(nil); 120 Player.AudioSystem := AudioSystem; 121 Playlist.Player := Player; 122 //Player.Active := True; 132 DefaultAudioSystem := SystemClass.Create(nil); 133 MediaPlayer.AudioSystem := DefaultAudioSystem; 134 PlayList.Player := MediaPlayer; 135 //MediaPlayer.Active := True; 123 136 end; 124 137 end; … … 127 140 procedure TFormMain.APlayExecute(Sender: TObject); 128 141 begin 129 Player.Play; 142 MediaPlayer.Play; 143 UpdateInterface; 130 144 end; 131 145 132 146 procedure TFormMain.APlayNextExecute(Sender: TObject); 133 147 begin 134 Play list.PlayNext;148 PlayList.PlayNext; 135 149 FormPlaylist.ReloadList; 136 150 end; … … 138 152 procedure TFormMain.APlayPreviousExecute(Sender: TObject); 139 153 begin 140 Play list.PlayPrevious;154 PlayList.PlayPrevious; 141 155 end; 142 156 … … 148 162 procedure TFormMain.AStopExecute(Sender: TObject); 149 163 begin 150 Player.Stop; 164 MediaPlayer.Stop; 165 UpdateInterface; 151 166 end; 152 167 153 168 procedure TFormMain.APauseExecute(Sender: TObject); 154 169 begin 155 Player.Pause; 170 MediaPlayer.Pause; 171 UpdateInterface; 156 172 end; 157 173 … … 159 175 begin 160 176 if OpenDialog1.Execute then begin 161 Player.FileName := OpenDialog1.FileName; 162 Playlist.AddFile(OpenDialog1.FileName); 163 Player.Play; 177 MediaPlayer.FileName := OpenDialog1.FileName; 178 PlayList.AddFile(OpenDialog1.FileName); 179 MediaPlayer.Play; 180 UpdateInterface; 164 181 end; 165 182 end;
Note:
See TracChangeset
for help on using the changeset viewer.