播放问题(0分)

  • 主题发起人 主题发起人 kongzhanwei
  • 开始时间 开始时间
K

kongzhanwei

Unregistered / Unconfirmed
GUEST, unregistred user!
下面是一个播放器程序,运行时老出现以下的问题,请问该如何解决。
(1)当我在filelistbox列表中双击一首歌曲名时,本来应该正常播放,可有时却会出现播放焦点依次下移,直至最后一首才能正常播放。
(2)当我拖动tScrollBar控件时,也会出现第一中情况,
请问我该怎么解决,谢谢!
源代码如下:
unit Unit1;


interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
jpeg, ExtCtrls, ComCtrls, StdCtrls, Buttons, MPlayer,mmsystem, FileCtrl;


type
TForm1 = class(TForm)
Image1: TImage;

StatusBar1: TStatusBar;

BitBtn1: TBitBtn;

BitBtn2: TBitBtn;

BitBtn3: TBitBtn;

BitBtn4: TBitBtn;

BitBtn5: TBitBtn;

BitBtn6: TBitBtn;

BitBtn7: TBitBtn;

BitBtn8: TBitBtn;

BitBtn9: TBitBtn;

BitBtn10: TBitBtn;

BitBtn11: TBitBtn;

BitBtn12: TBitBtn;

BitBtn13: TBitBtn;

BitBtn14: TBitBtn;

BitBtn15: TBitBtn;

BitBtn16: TBitBtn;

BitBtn17: TBitBtn;

BitBtn18: TBitBtn;

MediaPlayer1: TMediaPlayer;

OpenDialog1: TOpenDialog;

StaticText1: TStaticText;

StaticText2: TStaticText;

StaticText3: TStaticText;

StaticText4: TStaticText;

StaticText5: TStaticText;

StaticText6: TStaticText;

Timer1: TTimer;

TrackBar2: TTrackBar;

TrackBar3: TTrackBar;

ScrollBar1: TScrollBar;

FileListBox1: TFileListBox;

procedure BitBtn17Click(Sender: TObject);

procedure BitBtn14Click(Sender: TObject);

procedure Showtime(pos:longint);

procedure Timer1Timer(Sender: TObject);

procedure BitBtn10Click(Sender: TObject);

procedure BitBtn11Click(Sender: TObject);

procedure BitBtn12Click(Sender: TObject);

procedure BitBtn13Click(Sender: TObject);

procedure BitBtn9Click(Sender: TObject);

procedure BitBtn18Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure TrackBar2Change(Sender: TObject);

procedure TrackBar3Change(Sender: TObject);

procedure BitBtn16Click(Sender: TObject);

procedure FileListBox1DblClick(Sender: TObject);

procedure MediaPlayer1Notify(Sender: TObject);

procedure ScrollBar1Change(Sender: TObject);

procedure ScrollBar1Scroll(Sender: TObject;
ScrollCode: TScrollCode;

var ScrollPos: Integer);

private
procedure wmnchittest(var msg:twmnchittest);

message wm_nchittest;

{ Private declarations }
public
{ Public declarations }
end;



var
Form1: TForm1;

openflag:boolean;

formatflag:boolean;


implementation

uses Unit2, Unit3;


{$R *.DFM}
procedure TForm1.wmnchittest(var msg:twmnchittest);

begin

inherited;

if (htclient=msg.result) then
msg.result:=htcaption;

end;



procedure TForm1.Showtime(pos:longint);

var
hours,minutes,seconds:byte;

temp:longint;

begin

temp:=pos div 1000;

seconds:=temp mod 60;

temp:=temp div 60;

minutes:=temp mod 60;

hours:=temp div 60;

form1.StaticText1.caption:=inttostr(hours);

form1.StaticText2.caption:=inttostr(minutes);

form1.StaticText3.caption:=inttostr(seconds);

end;



procedure TForm1.BitBtn17Click(Sender: TObject);

begin

timer1.enabled:=false;

form1.Close;

end;



procedure TForm1.BitBtn14Click(Sender: TObject);

begin

form3.show;

end;



procedure TForm1.Timer1Timer(Sender: TObject);

begin

scrollbar1.position:=mediaplayer1.position;

showtime(mediaplayer1.position);

randomize;

form1.StatusBar1.color:=rgb(random(255),random(255),random(255));

form1.StatusBar1.SimpleText:=form1.MediaPlayer1.filename;

end;



procedure TForm1.BitBtn10Click(Sender: TObject);

begin

form1.MediaPlayer1.Play;

end;



procedure TForm1.BitBtn11Click(Sender: TObject);

begin

form1.MediaPlayer1.Pause;

end;



procedure TForm1.BitBtn12Click(Sender: TObject);

begin

form1.MediaPlayer1.stop;

end;



procedure TForm1.BitBtn13Click(Sender: TObject);

begin

form1.MediaPlayer1.next;

end;



procedure TForm1.BitBtn9Click(Sender: TObject);

begin

form1.MediaPlayer1.Previous;

end;



procedure TForm1.BitBtn18Click(Sender: TObject);

begin

showwindow(form1.Handle,sw_minimize);

end;



procedure TForm1.FormCreate(Sender: TObject);

var v:longint;

begin

waveoutgetvolume(0,@v);

trackbar2.position:=hi(v);

trackbar3.position:=hi(v);

form1.FileListBox1.Clear;

end;



procedure TForm1.TrackBar2Change(Sender: TObject);

var t,v:longint;

begin

t:=trackbar2.position;

waveoutgetvolume(0,@v);

v:=v and $ffff0000 or (t shl 8);

waveoutsetvolume(0,v);

end;



procedure TForm1.TrackBar3Change(Sender: TObject);

var t,v:longint;

begin

t:=trackbar3.position;

waveoutgetvolume(0,@v);

v:=(t shl 8) or (t shl 24);

waveoutsetvolume(0,v);

end;



procedure TForm1.BitBtn16Click(Sender: TObject);

begin

form2.show;

unit2.form2.PageControl1.Pages[1];

end;



procedure TForm1.FileListBox1DblClick(Sender: TObject);

begin

unit1.Form1.MediaPlayer1.filename:=unit1.Form1.FileListBox1.filename;

unit1.form1.MediaPlayer1.Open;

MediaPlayer1.Notify :=true;
//关键之处:该属性设为true 让MediaPlayer1成功调用
unit1.form1.MediaPlayer1.play;
//play方法之后能够响应ONNotify事件
end;



procedure TForm1.MediaPlayer1Notify(Sender: TObject);

begin

if filelistbox1.ItemIndex<filelistbox1.Items.Count then

begin

filelistbox1.ItemIndex:=filelistbox1.ItemIndex+1;

MediaPlayer1.FileName :=filelistbox1.FileName

MediaPlayer1.Open

if filelistbox1.ItemIndex=filelistbox1.Items.Count-1 then

MediaPlayer1.Notify :=false //当播放到最后一首时,停止响应ONNotify事件
else
MediaPlayer1.Notify :=true;

MediaPlayer1.play;

end;


end;



procedure TForm1.ScrollBar1Change(Sender: TObject);

begin

scrollbar1.position:=mediaplayer1.position;

showtime(mediaplayer1.position);

end;



procedure TForm1.ScrollBar1Scroll(Sender: TObject;
ScrollCode: TScrollCode;

var ScrollPos: Integer);

begin

mediaplayer1.pause;

mediaplayer1.Position:=scrollpos;

mediaplayer1.Play;

end;



end.
 
filelistbox1.ItemIndex:=filelistbox1.ItemIndex+1;

你的这句语句不就是让焦点依次下移吗?
 
procedure TForm1.FileListBox1DblClick(Sender: TObject);

begin

unit1.Form1.MediaPlayer1.filename:=unit1.Form1.FileListBox1.filename;

unit1.form1.MediaPlayer1.Open;

MediaPlayer1.Notify :=true;
//这里不必设置,去掉!到播放完时会自动触发的!
unit1.form1.MediaPlayer1.play;

end;


 

Similar threads

I
回复
0
查看
529
import
I
I
回复
0
查看
740
import
I
I
回复
0
查看
763
import
I
I
回复
0
查看
566
import
I
后退
顶部