Tạo playlist trong Windows Media Palyer với C#

Tạo playlist trong Windows Media Palyer với C#

Phương thức sau tạo playlist cho 1 control WindowsMediaPlayer.

private void CreatePlayLis(String folder,string extendsion)

{

string myPlaylist = “Sample”;

WMPLib.IWMPPlaylist pl;

WMPLib.IWMPPlaylistArray plItems;

plItems = windowsMediaPlayer.playlistCollection.getByName(myPlaylist);


if (plItems.count == 0)

pl = windowsMediaPlayer.playlistCollection.newPlaylist(myPlaylist);

else

pl = plItems.Item(0);


DirectoryInfo dir = new DirectoryInfo(folder);

FileInfo[] files = dir.GetFiles(extendsion, SearchOption.AllDirectories);


foreach (FileInfo file in files)

{

string musicFile01 = file.FullName;

string mName = file.Name;

ListViewItem item = new ListViewItem(mName);

musicList.Items.Add(item);


WMPLib.IWMPMedia m1 = windowsMediaPlayer.newMedia(musicFile01);

pl.appendItem(m1);

}

windowsMediaPlayer.currentPlaylist = pl;

windowsMediaPlayer.Ctlcontrols.play();

}

Bạn tạo 1 thể hiện của WindowsMediaPlayer controls windowsMediaPlayer sau đó gọi phương thức này trong nút load thư mục chứa các tập tin nhạc.

Các đoạn code còn lại của ứng dụng:

private void tsbLoadDirectry_Click(object sender, EventArgs e)

{

FolderBrowserDialog fld = new FolderBrowserDialog();

fld.SelectedPath = @”E:\Music\hoatau”;

if (fld.ShowDialog(this) == DialogResult.OK)

{

CreatePlayLis(fld.SelectedPath,tscomboExtension.Text);

}

}

private void musicList_DoubleClick(object sender, EventArgs e)

{

try

{

IWMPMedia med= windowsMediaPlayer.currentPlaylist.get_Item(musicList.SelectedIndices[0]);

ListViewItem sel = musicList.SelectedItems[0];

windowsMediaPlayer.Ctlcontrols.playItem(med);

}

catch (Exception)

{

}

}

private void tsbClearPlaylist_Click(object sender, EventArgs e)
{

for (int i = 0; i < windowsMediaPlayer.currentPlaylist.count; i++)

{

IWMPMedia med = windowsMediaPlayer.currentPlaylist.get_Item(i);

windowsMediaPlayer.currentPlaylist.removeItem(med);

}

musicList.Items.Clear();

}

Chúc may mắn!

Bạn thấy bài viết này như thế nào?: 
Average: 7 (1 vote)
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Ứng Dụng Gmail Cho iOS Đã Quay Trở Lại Trên App Store

Ứng Dụng Gmail Cho iOS Đã Quay Trở Lại Trên App Store

Và nay khi đã sửa xong các lỗi bug, Google đã đem ứng dụng này quay trở lại kho ứng dụng App Store.

Page Authority là gì?

Page Authority là gì?

Page Authority (PA) dự đoán khả năng có thể xếp hạng tốt cho một trang web bất kỳ mà không cần phải quan tâm đến nội dung. Một trang web có Page Authority càng cao thì cơ hội xếp hạng cho trang web ấy càng cao.

Ngày 7 giới thiệu Big Data – MapReduce là gì?

Ngày 7 giới thiệu Big Data – MapReduce là gì?

MapReduce được thiết kế bởi Google như 1 mô hình lập trình xử lý tập dữ liệu lớn song song, thuật toán được phân tán trên 1 cụm.

Công ty diệt chuột T&C

 

Diet con trung