我正在尝试动态加载 WindowsMediaPlayer 控件,但无法使其正常工作。
原样的代码似乎播放音频(可能还有视频),但未在表单上显示视频。表单保持空白,正在播放音频。(播放 WVM 文件,不能是编码器问题)我正在导入 WMPLib。
WindowsMediaPlayer videoPlayer;
public void createContent(Form form) {
PlayFile("F:\\Videos\\CantTouchThis.wmv");
}
private void PlayFile(string url) {
videoPlayer = new WindowsMediaPlayer();
videoPlayer.PlayStateChange +=
new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(Player_PlayStateChange);
videoPlayer.MediaError +=
new WMPLib._WMPOCXEvents_MediaErrorEventHandler(Player_MediaError);
videoPlayer.URL = url;
videoPlayer.controls.play();
}
private void Player_PlayStateChange(int NewState) {
if ((WMPLib.WMPPlayState)NewState == WMPLib.WMPPlayState.wmppsStopped) {
}
}
private void Player_MediaError(object pMediaObject) {
MessageBox.Show("Cannot play media file.");
}
帮助使其工作将不胜感激。