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);
//填充歌曲列表
...{
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);
}
}
}
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);
}
}