关于用visual studio2008调用windows media player 新人求问:用c#编写媒体播放器(调用windows media player),怎样获取当前文件播放时间以及文件播放总时间,还有设置怎样使播放器播完后自动退出。可以给出代码吗 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://topic.csdn.net/u/20101010/00/89E7D09B-7C59-4D74-A5E8-2248EA4C649D.html 如果你是用System.Diagnostics.Process.Start("foo.mp3");的方法播放的,无法获取这些信息。如果是用media player控件,则:axWindowsMediaPlayer1.URL = @"foo.mp3";axWindowsMediaPlayer1.PlayStateChange += onPlayStateChange;private void onPlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e){double duration = axWindowsMediaPlayer1.currentMedia.duration;//文件长度,获取一次就够了double currentPosition = axWindowsMediaPlayer1.Ctlcontrols.currentPosition;//当前文件位置,如果要在文件播放过程中检测,可将这句放到一个timer控件的事件里if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded){//媒体播放完 ...}}注意,如果是在64位windows 7系统下,需编译成x86,不能用缺省的anyCpu,不然这个事件不会被触发。如果是用winmm.dll,看这个链接:http://blog.csdn.net/baihe_591/article/details/2594041 播放完成:处理PlayStateChange 事件 8 MediaEnded应该是你想要的状态,然后退出程序即可。// Add a delegate for the PlayStateChange event.player.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e){ // Test the current state of the player and display a message for each state. switch (e.newState) { case 0: // Undefined currentStateLabel.Text = "Undefined"; break; case 1: // Stopped currentStateLabel.Text = "Stopped"; break; case 2: // Paused currentStateLabel.Text = "Paused"; break; case 3: // Playing currentStateLabel.Text = "Playing"; break; case 4: // ScanForward currentStateLabel.Text = "ScanForward"; break; case 5: // ScanReverse currentStateLabel.Text = "ScanReverse"; break; case 6: // Buffering currentStateLabel.Text = "Buffering"; break; case 7: // Waiting currentStateLabel.Text = "Waiting"; break; case 8: // MediaEnded currentStateLabel.Text = "MediaEnded"; break; case 9: // Transitioning currentStateLabel.Text = "Transitioning"; break; case 10: // Ready currentStateLabel.Text = "Ready"; break; case 11: // Reconnecting currentStateLabel.Text = "Reconnecting"; break; case 12: // Last currentStateLabel.Text = "Last"; break; default: currentStateLabel.Text = ("Unknown State: " + e.newState.ToString()); break; }} axWindowsMediaPlayer1.Ctlcontrols.currentPosition 当前positionThe currentPosition property gets or sets the current position in the media item in seconds from the beginning.http://msdn.microsoft.com/en-us/library/windows/desktop/dd564740(v=VS.85).aspxaxWindowsMediaPlayer1.currentMedia.duration 总长度A System.Double that is the duration in seconds.http://msdn.microsoft.com/en-us/library/windows/desktop/dd564790(v=VS.85).aspx 我写了if (MediaPlayer.playState == WMPLib.WMPPlayState.wmppsMediaEnded)Application.Exit();为什么文件播放完后,软件不能自动退出 player_PlayStateChange中设置个断点,完成后函数会被调用吗?如果调用了,看看playState 是什么 继续上次的 自定义容器写好了,现在要对容器里面的控件实现排序....如何实现 webform如何启动应用程序? .NET点击按钮关闭页面问题 socket 同步传输可不可以实现一个服务器与两个客户端之间传输 duwamish的一个问题,大家共参 如何开发一个背单词软件?如何收集英语词库? dataGridView控件邦定dataTable,当动态向dataTable添加数据时,当dataGridView需要使用滚动条时,程序会死 新手问个cristal report的问题 一个问题请教 新手报到,交朋识友 C# DTE解析一个*.cpp文件 高分求解啊~ 如何获取有效字段
axWindowsMediaPlayer1.PlayStateChange += onPlayStateChange;private void onPlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{double duration = axWindowsMediaPlayer1.currentMedia.duration;//文件长度,获取一次就够了double currentPosition = axWindowsMediaPlayer1.Ctlcontrols.currentPosition;//当前文件位置,如果要在文件播放过程中检测,可将这句放到一个timer控件的事件里if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
{//媒体播放完
...
}
}注意,如果是在64位windows 7系统下,需编译成x86,不能用缺省的anyCpu,不然这个事件不会被触发。如果是用winmm.dll,看这个链接:
http://blog.csdn.net/baihe_591/article/details/2594041
player.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
// Test the current state of the player and display a message for each state.
switch (e.newState)
{
case 0: // Undefined
currentStateLabel.Text = "Undefined";
break; case 1: // Stopped
currentStateLabel.Text = "Stopped";
break; case 2: // Paused
currentStateLabel.Text = "Paused";
break; case 3: // Playing
currentStateLabel.Text = "Playing";
break; case 4: // ScanForward
currentStateLabel.Text = "ScanForward";
break; case 5: // ScanReverse
currentStateLabel.Text = "ScanReverse";
break; case 6: // Buffering
currentStateLabel.Text = "Buffering";
break; case 7: // Waiting
currentStateLabel.Text = "Waiting";
break; case 8: // MediaEnded
currentStateLabel.Text = "MediaEnded";
break; case 9: // Transitioning
currentStateLabel.Text = "Transitioning";
break; case 10: // Ready
currentStateLabel.Text = "Ready";
break; case 11: // Reconnecting
currentStateLabel.Text = "Reconnecting";
break; case 12: // Last
currentStateLabel.Text = "Last";
break; default:
currentStateLabel.Text = ("Unknown State: " + e.newState.ToString());
break;
}
}
The currentPosition property gets or sets the current position in the media item in seconds from the beginning.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd564740(v=VS.85).aspx
axWindowsMediaPlayer1.currentMedia.duration 总长度
A System.Double that is the duration in seconds.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd564790(v=VS.85).aspx
if (MediaPlayer.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
Application.Exit();为什么文件播放完后,软件不能自动退出