鱼C论坛

 找回密码
 立即注册
查看: 3984|回复: 7

dephi怎样把多个音乐添加到WindowsMediaPlayer控件中的播放列表中

[复制链接]
发表于 2012-7-7 14:42:41 | 显示全部楼层 |阅读模式
5鱼币
dephi怎样把多个音乐添加到WindowsMediaPlayer控件中的播放列表中
俺最近想做一个音乐播放器,现在就是想把一个文件夹里的音乐全部添加到WindowsMediaPlayer控件中的播放列表中并且把它们都显示在一个可视化的空间列表中(比如listbox),希望大家给点意见。

最佳答案

查看完整内容

不好意思 这几天忙没上网 不知道楼主问题解决了没 刚才自己做了个样本 主要代码是我把源码文件上传了 可以看看这个帖子 http://bbs.fishc.com/forum.php?mod=viewthread&tid=19757&extra=
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2012-7-7 14:42:42 | 显示全部楼层
不好意思 这几天忙没上网 不知道楼主问题解决了没 刚才自己做了个样本 主要代码是
procedure TForm1.DoSearchPathFile(qPath:   string);
var 
  SR:TSearchRec;
  FileAttr:Integer;
begin
FileAttr:=faDirectory;
FindFirst(qPath + '\*.*',FileAttr,SR);
While   FindNext(SR)   =   0   do
begin
  if   (SR.Name <> '.')   and   (SR.Name <> '..')   then
  begin
    if   DirectoryExists(qPath   +   '\'   +   SR.Name)   then
    begin
        ListView1.Items.Add.Caption:=qPath + '\' + SR.Name;
        DoSearchPathFile(qPath + '\' + SR.Name);
    end;
  end;
end;

FileAttr:=faAnyFile;
FindFirst(qPath + '\*.*', FileAttr,SR);
while FindNext(SR)=0 do
begin
  if   (SR.Name   <>   '.')   and   (Sr.Name   <>   '..')   then
  begin
     if   not(DirectoryExists(qPath   +   '\'   +   SR.Name))   then
     begin
        ListView1.Items.Add.Caption:=qPath + '\' + SR.Name;
     end;
  end;
end;
end;
procedure TForm1.OpenfExecute(Sender: TObject);//打开文件夹所有文件到列表
var
  s:string;
begin
 if SelectDirectory('请选择媒体文件目录','',s) then
 DoSearchPathFile(s);
end;
我把源码文件上传了  可以看看这个帖子
http://bbs.fishc.com/forum.php?mod=viewthread&tid=19757&extra=
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2012-7-7 19:55:17 | 显示全部楼层
本帖最后由 aminghanhua 于 2012-7-7 21:55 编辑

楼主的意思不太清楚
1、如果用三个控件DriveComboBox1    DirectoryListBox1   FileListBox1 和一个MediaPlayer1
DriveComboBox1的 dirlist事件选择DirectoryListBox1,DirectoryListBox1的filelist事件选择FileListBox1,FileListBox1的mask属性为 *.mp3  这样就全都为mp3了  再在filelistbox1的onclick事件加入
  mediaplayer1.FileName:=filelistbox1.FileName;
  mediaplayer1.Open;
等代码。

2、点击按钮打开文件夹,所有mp3文件自动添加到列表中
(1)用SelectDirectory打开文件夹  要 uses   FileCtrl;  加入个全局变量list1: TListItem;
(2)放入一个button1控件用来打开文件夹,一个button2按钮用来播放 一个listview1控件用来显示歌曲 和一个MediaPlayer1
(3)listview的viewstyle改为vsreport   双击listview1控件 点击add new 加入两个 caption分别为 文件名 和 路径
(4)具体代码
function AddFormDir(F: string): integer; //查找MP3文件的函数
var
MP3: integer;
S: TSearchRec;
i: Integer;
a: Boolean;
begin
mp3 := FindFirst(F, faAnyFile, s); //查找*.mp3
while mp3 = 0 do
begin
Application.ProcessMessages;
if (S.Attr and faDirectory) = 0 then
begin
a := False;
for i := 0 to Form1.ListView1.Items.Count - 1 do
begin
if GetCurrentDir + '\' + s.Name =Form1.ListView1.Items[i].SubItems.Strings[0] + Form1.ListView1.items[i].Caption then
a:= True;
end;
if a = false then
begin
list1:=Form1.ListView1.Items.Add;
list1.Caption := s.name;
list1.SubItems.add(GetCurrentDir + '\');
form1.Button1.Enabled := true;
end;
end;
MP3 := FindNext(s);
end;
result := 1;
end;

procedure TForm1.Button1Click(Sender: TObject);//button1的onclick事件加入代码 //添加文件夹中的MP3文件
var
dir: string;
S: TSearchRec;
begin
if selectdirectory('请选择目录', '', dir) then
begin
ChDir(Dir); //设置当前路径为搜索目录
AddFormDir('*.mp3');
end;
FindClose(s);
end;


procedure TForm1.Button2Click(Sender: TObject); //播放
begin
if ListView1.ItemIndex <> -1 then //首先判断列表框中是否有内容
begin
mediaplayer1.FileName := listview1.Selected.SubItems.Strings[0] + listview1.Selected.Caption;
begin
try
mediaplayer1.Open;
mediaplayer1.Play; //播放列表框中选择的文件
mediaplayer1.Notify := true;
except
on EMCIDeviceError do
MessageBox(Handle, '无法播放,请检查路径或者文件名是否正确!', '错误',
MB_OK + MB_ICONSTOP);
end;
end;
end;
end;

procedure TForm1.ListView1DblClick(Sender: TObject);//双击listview播放
begin
Button2Click(sender);
end;





想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2012-7-7 22:52:24 | 显示全部楼层
本帖最后由 aminghanhua 于 2012-7-7 22:59 编辑

也可在Button1Click事件中 加入AddFormDir('*.wav');    AddFormDir('*.wma');等等其它音频文件
两种方法都行 测试通过 给分
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2012-7-8 13:04:32 | 显示全部楼层

神马意思不懂啊能不能说的具体点
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2012-7-8 13:06:25 | 显示全部楼层
aminghanhua 发表于 2012-7-7 19:55
楼主的意思不太清楚
1、如果用三个控件DriveComboBox1    DirectoryListBox1   FileListBox1 和一个MediaP ...

这位老兄首先十分的感谢你,但是你貌似没看清我想表达的意思就是我的控件是windowsMediaPlayer,而不是MediaPlayer这两个是有区别的喔
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2012-7-8 21:36:33 | 显示全部楼层
Sorry  没弄明白 你说的是WindowsMediaPlayer这个ActiveX控件吧
明天跟帖吧 要睡了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2012-7-10 16:54:01 | 显示全部楼层
aminghanhua 发表于 2012-7-8 21:36
Sorry  没弄明白 你说的是WindowsMediaPlayer这个ActiveX控件吧
明天跟帖吧 要睡了

恩是啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-6 05:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表