播放流媒体
来源:互联网 发布:巧克力 知乎 编辑:程序博客网 时间: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);
}
}
你要是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);
}
}
- 播放流媒体
- RTSP流媒体播放分析
- RTSP流媒体播放分析
- Android流媒体播放器
- Android流媒体播放器
- Android流媒体播放器
- Android流媒体播放器
- Android流媒体播放器
- Android流媒体播放器
- httplive流媒体播放(m3u8)
- 流媒体播放方式
- IOS流媒体播放
- RTSP流媒体播放分析
- RTSP 流媒体播放地址
- RTMP流媒体播放过程
- IOS流媒体播放
- RTMP流媒体播放过程
- 流媒体播放器
- 法家思想简介(转)
- web excel 导入出
- 给网吧使用的Nat+Iptables+Squid的脚本
- asp常用函数集
- javascript基本知识参考手册
- 播放流媒体
- 做到实处[原创]
- 什么是IIS应用程序池以及应用程序池详解
- BBSGood.Speed Version 4.0注入漏洞
- 使用vsftpd构建安全的FTP服务
- [转贴]Apache+PHP5+MySQL4(5)+PHPMyAdmin 的简易安装配置
- GNU CC核心扩展
- 基本的浮动原理http://www.52css.com/article.asp?id=229
- java中变量的介绍