播放流媒体

来源:互联网 发布:巧克力 知乎 编辑:程序博客网 时间:2024/04/28 08:51
Interop.MediaPlayer.dll 
你要是C#.net来写的话,是不需要通过API调用,只需要应用一写这个Dll就可以了. 
我写的一个Demo     部分源码 
private   void   button1_Click(object   sender,   System.EventArgs   e) 
{//浏览MP3文件 
if(this.openFileDialog1.ShowDialog()==DialogResult.OK) 

this.listView1.Items.Clear(); 
string   []FileNames=this.openFileDialog1.FileNames; 
foreach(string   FileName   in   FileNames) 

//取得文件大小 
FileInfo   MyFileInfo=new   FileInfo(FileName); 
float   MyFileSize=(float)MyFileInfo.Length/(1024*1024); 
this.axMediaPlayer1.FileName=FileName; 
//取得作者信息 
string   MyAuthor=this.axMediaPlayer1.GetMediaInfoString(MediaPlayer.MPMediaInfoType.mpClipAuthor); 
//取得不含路径的文件名 
string   MyShortFileName=FileName.Substring(FileName.LastIndexOf("/")+1); 
MyShortFileName
=MyShortFileName.Substring(0,MyShortFileName.Length-4); 
//填充歌曲列表 
string[]   SubItem={MyShortFileName,MyAuthor,MyFileSize.ToString().Substring(0,4)+"M",FileName}
ListViewItem   Item
=new   ListViewItem(SubItem); 
this.listView1.Items.Add(Item); 
this.listView1.Items[0].Selected=true
}
 

}
 
}
 

private   void   button2_Click(object   sender,   System.EventArgs   e) 
{//播放MP3文件 
if(this.listView1.Items.Count> 0

if(this.listView1.SelectedItems.Count> 0

int   iPos=this.listView1.SelectedItems[0].Index; 
string   FileName=this.listView1.Items[iPos].SubItems[3].Text; 
this.axMediaPlayer1.FileName=FileName; 
this.axMediaPlayer1.Play(); 
}
 
}
 
else 

MessageBox.Show(
"请选择歌曲!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information); 
}
 
}
 


private   void   button4_Click(object   sender,   System.EventArgs   e) 
{//暂停播放 
if(this.axMediaPlayer1.FileName.Length> 0
this.axMediaPlayer1.Pause(); 
else 

MessageBox.Show(
"请选择歌曲!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information); 
}
 
}
 

private   void   button5_Click(object   sender,   System.EventArgs   e) 
{//停止播放 
if(this.axMediaPlayer1.FileName.Length> 0
this.axMediaPlayer1.Stop(); 
else 

MessageBox.Show(
"请选择歌曲!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information); 
}
 
}
 

private   void   button6_Click(object   sender,   System.EventArgs   e) 
{//上一首歌曲 
if(this.listView1.Items.Count> 0

if(this.listView1.SelectedItems.Count> 0

int   iPos=this.listView1.SelectedItems[0].Index; 
if(iPos> 0

this.listView1.Items[iPos-1].Selected=true
string   FileName=this.listView1.Items[iPos-1].SubItems[3].Text; 
this.axMediaPlayer1.FileName=FileName; 
this.axMediaPlayer1.Play(); 
}
 
else 

MessageBox.Show(
"已经是第一首歌曲!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information); 
}
 
}
 
}
 
else 

MessageBox.Show(
"请选择歌曲!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information); 
}
 
}
 

private   void   button7_Click(object   sender,   System.EventArgs   e) 
{//下一首歌曲 
if(this.listView1.Items.Count> 0

if(this.listView1.SelectedItems.Count> 0

int   iPos=this.listView1.SelectedItems[0].Index; 
if(iPos <this.listView1.Items.Count-1

this.listView1.Items[iPos+1].Selected=true
string   FileName=this.listView1.Items[iPos+1].SubItems[3].Text; 
this.axMediaPlayer1.FileName=FileName; 
this.axMediaPlayer1.Play(); 
}
 
else 

MessageBox.Show(
"已经是最后一首歌曲!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information); 
}
 
}
 
}
 
else 

MessageBox.Show(
"请选择歌曲!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information); 
}
 

}