📄 ueplayer.pas
字号:
end;
end;
procedure TfrmEPlayer.SpeedBtn_DownClick(Sender: TObject);
begin
if frmPlayList.ListBox_PlayFiles.ItemIndex < 0 then
MessageBox(Handle,'此时没有任何播放文件!',PChar('警告'),MB_OK+MB_ICONWARNING)
else
begin
MediaPlayer.Stop;
frmPlayList.ListBox_PlayFiles.ItemIndex := frmPlayList.ListBox_PlayFiles.ItemIndex + 1;
MediaPlayer.FileName := frmPlayList.ListBox_PlayFiles.Items[frmPlayList.ListBox_PlayFiles.ItemIndex];
MediaPlayer.Open;
MediaPlayer.Play;
end;
end;
procedure TfrmEPlayer.N2Click(Sender: TObject);
begin
OpenDlg_Files.Options := [ofHideReadOnly,ofAllowMultiSelect,ofEnableSizing];
try
if OpenDlg_Files.Execute then
begin
frmPlayList.ListBox_PlayFiles.Items.AddStrings(OpenDlg_Files.Files);
frmPlayList.ListBox_PlayFiles.ItemIndex := 0;
end;
finally
SpeedBtn_Play.Enabled := True;
end;
end;
procedure TfrmEPlayer.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if MessageBox(Handle, '确认关闭程序吗?', '警告', MB_OKCANCEL+MB_ICONWARNING) = IDOK then
begin
if frmPlayList <> nil then
frmPlayList.Free;
Application.Terminate;
end
else
Action := caNone;
end;
procedure TfrmEPlayer.FormCreate(Sender: TObject);
var
StopTime: DWord;
I: Integer;
begin
StopTime := GetTickCount div 1000;
while ((GetTickCount div 1000) < (StopTime + 1)) do
Sleep(1);
PositionChange := False;
for I := 0 to MAXGENRES do
cbx_Genre.Items.Add(GenresTable[I]);
ResetText;
end;
// 打开CD-ROM
procedure TfrmEPlayer.CDROM1Click(Sender: TObject);
begin
MCISendString('set cdaudio door open wait', nil, 0, Handle);
end;
// 关上CD-ROM
procedure TfrmEPlayer.CDROM2Click(Sender: TObject);
begin
MCISendString('set cdaudio door closed wait', nil, 0, Handle);
end;
procedure TfrmEPlayer.TrackBar1Change(Sender: TObject);
var
t, v: Longint;
begin
t := TrackBar1.Position;
v := (t shl 8)or(t shl 24);
waveOutSetVolume(0, v);
end;
procedure TfrmEPlayer.Timer_PlayTimer(Sender: TObject);
begin
with MediaPlayer do
begin
if Mode in [mpPlaying] then
begin
if frmPlayList.IsFileChange then
begin
TrackBar_Play.Max := MediaPlayer.Length div 1000;
TrackBar_Play.Position := 0;
lbl_TotalTime.Caption := '总时间: ' + ZeroFill(2, IntToStr(TrackBar_Play.max div 60))
+':' + ZeroFill(2, IntToStr(TrackBar_play.max mod 60))+' ';
frmPlayList.IsFileChange := False;
end;
TrackBar_Play.Position := Position div 1000;
lbl_PlayTime.Caption := '播放时间: ' + ZeroFill(2, IntToStr(TrackBar_Play.Position div 60))
+ ':' + ZeroFill(2, IntToStr(TrackBar_Play.Position mod 60)) + ' ';
//Label_Title.Caption := '当前曲目:' + '[' + ExtractFileName(frmPlayList.ListBox_PlayFiles.Items.Strings[frmPlayList.ListBox_PlayFiles.ItemIndex]) + ']';
Label_Title.Caption := '当前曲目:' + ExtractFileName(frmPlayList.ListBox_PlayFiles.Items.Strings[frmPlayList.ListBox_PlayFiles.ItemIndex]);
end;
end;
end;
procedure TfrmEPlayer.SpeedBtn_PlayClick(Sender: TObject);
var
I: Integer;
begin
if frmPlayList.ListBox_PlayFiles.ItemIndex < 0 then
MessageBox(Handle,'此时没有任何播放文件!',PChar('警告'),MB_OK+MB_ICONWARNING)
else
for I := 0 to frmPlayList.ListBox_PlayFiles.ItemIndex do
MediaPlayer.FileName := frmPlayList.ListBox_PlayFiles.Items.Strings[I];
MediaPlayer.Open;
MediaPlayer.Play;
end;
procedure TfrmEPlayer.btn_ShowPlayListClick(Sender: TObject);
begin
frmPlayList := TfrmPlayList.Create(Self);
frmPlayList.Show;
end;
procedure TfrmEPlayer.TrackBar_PlayChange(Sender: TObject);
begin
if (TrackBar_Play.Position <> (Mediaplayer.Position div 1000)) then PositionChange := True
else PositionChange := False;
if PositionChange then
with Mediaplayer do
begin
if Mode in [mpOpen, mpPlaying] then
begin
Pause;
Position := TrackBar_Play.Position * 1000;
Play;
end
else if mode in [mpOpen, mpPaused, mpStopped] then
begin
Position := TrackBar_play.Position * 1000;
end;
end;
end;
procedure TfrmEPlayer.Panel1Click(Sender: TObject);
begin
with TfrmAbout.Create(Application) do
begin
try
frmAbout.ShowModal;
finally
Free;
end;
end;
end;
procedure TfrmEPlayer.ResetText;
begin
lbl_Info.Caption := '';
edt_Title.Text := '';
edt_Artist.Text := '';
edt_Album.Text := '';
edt_Year.Text := '';
edt_Comment.Text := '';
cbx_Genre.Text := '';
end;
procedure TfrmEPlayer.btn_WriteTagClick(Sender: TObject);
var
ID3: TID3Tag;
begin
MP3FilePath := MediaPlayer.FileName;
if MP3FilePath ='' then Exit;
with MediaPlayer do
begin
if Mode in [mpPlaying] then
Close;
end;
ID3 := TID3Tag.Create;
ID3.FileName := MP3FilePath;
with ID3 do
begin
Title:= edt_Title.Text;
Artist := edt_Artist.Text;
Album := edt_Album.Text ;
Year := edt_Year.Text ;
Comment := edt_Comment.Text;
Genre := cbx_Genre.ItemIndex;
if WriteTag then
ShowMessage('WriteTag OK')
else
ShowMessage('WriteTag Fail');
Free;
end;
end;
procedure TfrmEPlayer.btn_RemoveTagClick(Sender: TObject);
var
ID3: TID3Tag;
// IDInfo: string;
begin
MP3FilePath := MediaPlayer.FileName;
if MP3FilePath ='' then Exit;
with MediaPlayer do
begin
if Mode in [mpPlaying] then
Close;
end;
ID3 := TID3Tag.Create;
ID3.FileName := MP3FilePath;
if ID3.RemoveTag then
begin
ResetText;
Showmessage('Remove OK');
end else
ShowMessage('Remove Tag Fail');
ID3.Free;
end;
procedure TfrmEPlayer.btn_ID3TagClick(Sender: TObject);
var
HDInfo: TMPEGAFormat;
ID3: TID3Tag;
FStream: TFileStream;
s: string;
begin
MP3FilePath := MediaPlayer.FileName;
if MP3FilePath ='' then Exit;
with MediaPlayer do
begin
if Mode in [mpPlaying] then
Close;
end;
if MP3FilePath = '' then Exit;
ResetText;
ID3 := TID3Tag.Create;
ID3.FileName := MP3FilePath;
if ID3.ReadTag then
with ID3 do
begin
edt_Title.Text := Title;
edt_Artist.Text := Artist;
edt_Album.Text := Album;
edt_Year.Text := Year;
edt_Comment.Text := Comment;
if Genre <= MAXGENRES then
cbx_Genre.ItemIndex := Genre
else
cbx_Genre.Text := 'Unknown';
ID3.Free;
end
else
ShowMessage('ReadTag fail');
HDInfo := TMPEGAFormat.Create;
FStream := TFileStream.Create(MP3FilePath, fmOpenRead);
if HDInfo.GetinfoFromStream(FStream) then
with HDInfo do
begin
s := 'MPEG 版本:' + IntToStr(Version) + #13 +
'位率(kbps):' + IntToStr(KBitRate) + #13 +
'采样频率(HZ):' + IntToStr(SamplingRate) + #13 +
'帧长度(字节):' + IntToStr(FrameLen) + #13 +
'帧数:' + IntToStr(Frames) + #13 +
'播放时间(单位毫秒):' + IntToStr(Len) + #13 +
'压缩层次:' + IntToStr(Layer) + #13 +
'填料长度:' + IntToStr(PaddingLen) + #13 +
'声道模式:' + IntToStr(ChannelMode) + #13 +
'声道扩展模式:' + ChannelModeExtStr + #13 +
'Emphasis:' + Emphasisstr + #13 + '版权:';
if Copyright then
s := s + '有' else s := s + '否';
if Original then
s := s + ' Original:Yes' else
s := s + ' Original:No';
lbl_Info.Caption := s;
end;
HDInfo.Free;
Fstream.Free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -