标题:播放器
只看楼主
缘来
Rank: 1
等 级:新手上路
帖 子:135
专家分:0
注 册:2006-11-18
 问题点数:0 回复次数:2 
播放器
我正在写一个媒体播放器。在写“文件--->打开”功能时,遇到了困难:
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Window Media 文件(*.asf;*.wm;*.wma)|*.asf;*.wm;*.wma|媒体播放表(*.asx;*.wax;*.m3u;*.wvx)|*.asx;*.wax;*.m3u;*.wvx|电影文件(MPEG)(*.mpeg;*.mpg)|*.mpeg;*.mpg|视频文件(*.avi;*.wmv)|*.avi;*.wmv|所有文件(*.*)|*.*";
if(ofd.ShowDialog()==DialogResult.OK)
{
try
{
string mediaPath = ofd.FileName;
axWindowsMediaPlayer1.FileName=mediaPath;
axWindowsMediaPlayer1.play();
}
catch
{
MessageBox.Show("无法播放此文件", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
为什么axWindowsMediaPlayer1的FileName属性不可用?
搜索更多相关主题的帖子: 媒体播放器 wax ofd 文件 mpeg 
2007-03-22 12:49
znbinger
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2006-11-18
得分:0 
你这个写法是不是有问题?
Player MyPlayer = new Player(MyPlayer);
openFileDialog1.Title = "打开音乐";
openFileDialog1.Filter = "媒体文件 (*.Mp3)|*.Mp3|媒体文件 (*.Wma)|*.Wma,*.Wma";
openFileDialog1.ShowDialog();
if(this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
  string path = this.openFileDialog1.FileName;
  FileInfo f = new FileInfo(path);
  MyPlayer.AddFile(f.FullName);
  string STRFILE = Convert.ToString(MyPlayer.NumOfMusic);
  for(int i = 1;i<=5-STRFILE.Length;i++)
{
STRFILE+="";
  STRFILE += f.Name;
  this.listBox1.Items.Add(STRFILE);
}
}

我这个能用呀!

不要什么都无所谓,干活才能挣钱呀!
2007-03-22 17:19
znbinger
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2006-11-18
得分:0 

这些是播放时候一些用到的东西 你可以参考一下 写的不是很完整亚!(player.cs 类)
class Player
{
private AxWMPLib.AxWindowsMediaPlayer myPlayer;
private string[] playList;
private int numOfMusic;
private int currentPlay;

public int NumOfMusic
{
get
{
return numOfMusic;
}
}

public WMPLib.WMPPlayState playstate
{
get
{
return myPlayer.playState;
}
}

public string PlayList(int num)
{
return playList[num];
}

public Player(AxWMPLib.AxWindowsMediaPlayer mediaPlayer)
{
myPlayer = mediaPlayer;
playList = new string[1000];
numOfMusic = 0;
}

public void AddFile(string path)
{
if (numOfMusic < 1000)
{
numOfMusic++;
playList[numOfMusic] = path;
}
}

public void DelFile(int selectNum)
{
for (int i = selectNum; i <= numOfMusic - 1; i++)
{
playList[i] = playList[i + 1];
}
numOfMusic--;
}

public void play(int selectNum)
{
myPlayer.URL = playList[selectNum];
currentPlay = selectNum;
}

public int NextPlay(int type)
{
/* type = 0 顺序

type = 1 重复播放全部
type = 2 重复播放一首
type = 3 随机播放

*/

switch (type)
{
case 0:
currentPlay++;
if (currentPlay > numOfMusic) return 0;
else return currentPlay;
case 1:
currentPlay++;
if (currentPlay > numOfMusic) return 1;
else return currentPlay;
case 2:
return currentPlay;
case 3:
Random rdm = new Random(unchecked((int)DateTime.Now.Ticks));
currentPlay = rdm.Next() % numOfMusic;
if (currentPlay == 0) return numOfMusic;
else return currentPlay;
default:
return 0;
}
}
}


不要什么都无所谓,干活才能挣钱呀!
2007-03-22 17:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-125844-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.645895 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved