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

 
August's hottest apps to download

Best Apps 2011: This year's hottest apps

As the Apple App Store, Android Market and BlackBerry App World continue to swell, keeping an eye on the apps that are actually of any use remains a trickier task than ever.

iPhone 4S trở thành smartphone chụp ảnh phổ biến thứ 2 trên Flickr

iPhone 4S trở thành smartphone chụp ảnh phổ biến thứ 2 trên Flickr

Chỉ một tháng sau khi phát hành, iPhone 4S đã nhanh chóng lọt vào top những smartphone chụp ảnh phổ biến chia sẻ ảnh lên mạng Flickr.

70 Best Free Google Android Apps(P4)

Những ứng dụng mua hàng trực tuyến từ android

Some months back we mentioned about 21 Best Google Android Applications, now today we present you 70 Free Google Android apps...

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

 

Diet con trung