delphi怎么样用 WindowsMediaPlayer1实现循环播放listbox播放列表中的文件 ( 积分: 100 )

  • 主题发起人 主题发起人 scansoft
  • 开始时间 开始时间
S

scansoft

Unregistered / Unconfirmed
GUEST, unregistred user!
播放列表是listbox
怎么样实现WindowsMediaPlayer1顺序播放,随机播放listbox列表中的文件,也就是播完一首自动播放下一首,
大哥大姐们帮小弟一把,小弟新手,最好把代码施舍给小弟!
 
问题补充:

listbox播放列表的实现代码是如下:
type
PRec = ^TRec;
TRec = record
Name : string;
Address : string;
end;


//增加
procedure TForm1.Button2Click(Sender: TObject);
var
rec : PRec;
begin

new(rec);
rec.Name := 'aaa';
rec.Address := 'c:/aaa.mp3';
listbox1.Items.AddObject(rec.Name, TObject(rec));
end;


//读
procedure TForm1.Button3Click(Sender: TObject);
begin

ShowMessage(PRec(listbox1.Items.Objects[0]).Name);
ShowMessage(PRec(listbox1.Items.Objects[0]).Address);
end;


//删除
procedure TForm1.Button4Click(Sender: TObject);
begin

Dispose(PRec(listbox1.Items.Objects[0]));
listbox1.Items.Delete(0);

end;

请大哥大姐们帮小弟实现WindowsMediaPlayer1顺序播放,随机播放listbox列表中的文件
 
//以前写的代码,播放下一个曲子的代码参考一下吧:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, FileCtrl, MPlayer;

type
TForm1 = class(TForm)
Button1: TButton;
mediaplayer1: TMediaPlayer;
FileListBox1: TFileListBox;
Memo1: TMemo;
Button2: TButton;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure SetNextMusicName();
procedure ShowMode(m: TMPModes);
procedure mediaplayer1Notify(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;
N: word;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin

N:= 0;
FileListBox1.Directory:= ExtractFilePath(Application.ExeName);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin

with mediaplayer1do

begin

Close;
FileName:= ExtractFilePath(Application.ExeName) +
FileListBox1.Items[N];
Open;
Play;
end;

end;


procedure TForm1.SetNextMusicName;
begin

if N = FileListBox1.items.Count - 1 then

N:= 0
else

Inc(N);
with mediaplayer1do

FileName:= ExtractFilePath(Application.ExeName) +
FileListBox1.Items[N];
end;


procedure TForm1.ShowMode(m: TMPModes);
begin

case m of
mpNotReady: Memo1.Lines.Add('mpNotReady');
mpStopped: Memo1.Lines.Add('mpStopped');
mpPlaying: Memo1.Lines.Add('mpPlaying');
mpRecording:Memo1.Lines.Add('mpRecording');
mpSeeking: Memo1.Lines.Add('mpSeeking');
mpPaused: Memo1.Lines.Add('mpPaused');
mpOpen: Memo1.Lines.Add('mpOpen');
else

Memo1.Lines.Add('???');
end;

end;


procedure TForm1.mediaplayer1Notify(Sender: TObject);
begin

with mediaplayer1do

begin

If Position= Length then

begin

Close;
SetNextMusicName();
Open;
play;
ShowMode(Mode);
end;

Notify:= true;
end;

end;


procedure TForm1.Button2Click(Sender: TObject);
begin

mediaplayer1.Pause;
end;


procedure TForm1.Button3Click(Sender: TObject);
begin

if mediaplayer1.Mode = mpPaused then

mediaplayer1.Play;
end;


end.
 
如果你用list作为列表的话用一个timer监视当前歌曲播放状态,先记住该歌曲在list中的index,然后自动选择下一个播放,别的没有什么好的办法,delphi中自带的mediaplayer不如activeX的mediaplayer功能多
 
1:WindowsMediaPlayer.currentPlayList.XXXXXXX
循环可以设置
WindowsMediaPlayer.settings.setMode方法。具体参看MSDN或者微软站点上WindowsMediaPlayer SDK
2:procedure TForm1.AddPlayFileToPlayList(const AFile: string;
IsUrl: Boolean = False);
var
ListItem: TListItem;
LyricFile: string;
currPlayList: IWMPPlaylist;
newMedia: IWMPMedia;
begin

ListItem := lvPlayList.Items.Add;
ListItem.ImageIndex := 0;
ListItem.Caption := ExtractFileName(AFile);
ListItem.SubItems.Add(AFile);
if not IsUrl then

begin

...
end;

if Player.currentPlaylist = nil then

begin

currPlayList := Player.newPlaylist('', '');
Player.currentPlaylist := currPlayList;
end;

newMedia := Player.newMedia(AFile);
Player.currentPlaylist.appendItem(newMedia);
Player.currentMedia := newMedia;
end;


最主要的还是
var
NewMedia: IWMPMedia;
begin

NewMedia := WindowsMediaPlayer1.newMedia('c:/abc.wmv');
WindowsMediaPlayer1.currentPlayList.appendItem(NewMedia);
WindowsMediaPlayer1.controls.play;
end;
 
后退
顶部