Windows Media Player出现问题 [英] Problem with Windows Media Player

查看:125
本文介绍了Windows Media Player出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想启动我的媒体播放器,但是我收到错误



错误1类型'WMPLib.WMPPlayState'在未引用的程序集中定义。您必须添加对程序集'WMPLib,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'的引用。 H:\ UCILISNO ZVONO \ WindowsFormsApplication1 \Form1.cs 319 13 WindowsFormsApplication1



错误3'WMPLib.IWMPControls'不包含'play'的定义没有扩展方法'play'接受类型'WMPLib.IWMPControls'的第一个参数可以找到(你是否缺少using指令或程序集引用?)H:\ UCILISNO ZVONO \ WindowsFormsApplication1 \Form1.cs 330 51 WindowsFormsApplication1

Hello, i want to start my media player but i get error

Error 1 The type 'WMPLib.WMPPlayState' is defined in an assembly that is not referenced. You must add a reference to assembly 'WMPLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. H:\UCILISNO ZVONO\WindowsFormsApplication1\Form1.cs 319 13 WindowsFormsApplication1

Error 3 'WMPLib.IWMPControls' does not contain a definition for 'play' and no extension method 'play' accepting a first argument of type 'WMPLib.IWMPControls' could be found (are you missing a using directive or an assembly reference?) H:\UCILISNO ZVONO\WindowsFormsApplication1\Form1.cs 330 51 WindowsFormsApplication1

private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
    axWindowsMediaPlayer2.URL = @"";
    //zavrsila pesnata
    if (axWindowsMediaPlayer2.playState.ToString() != "MediaEnded")
    {
        winmediaplayerstart();
    }
}
private void winmediaplayerstart()
{
    var url = axWindowsMediaPlayer2.URL;
    if (url != "")
    {
        axWindowsMediaPlayer2.URL = @"C:\ZVONO\pesni\OneRepublic - Counting Stars.mp4";
        axWindowsMediaPlayer2.Ctlcontrols.play();
    }
    else
    {
        DirectoryInfo d = new DirectoryInfo(@"" + folderpesni);
        FileInfo[] Files = d.GetFiles("*.mp4");
        foreach (FileInfo file in Files)
        {
            MessageBox.Show(file.Name);
        }
    }

}
private void winmediaplayerstop()
{
    axWindowsMediaPlayer2.Ctlcontrols.pause();
}

推荐答案

我会做一些建议的更改,因为代码中的一些内容是不对:

if(axWindowsMediaPlayer2.playState.ToString()!=MediaEnded)



为什么要尝试将playstate属性转换为字符串?如果您想知道播放状态是什么,则应使用为该事件提供的正确方法。像这样:



PlayStateChangeEvent

Hi, I will make some suggested changes as a couple of things in your code are not right:
if (axWindowsMediaPlayer2.playState.ToString() != "MediaEnded")

Why are you trying to convert the playstate property to a string? If you want to know what the play state is, you should use the correct methods provided for that event. Like so:

PlayStateChangeEvent
if (axWindowsMediaPlayer2.playState == WMPLib.WMPPlayState.wmppsStopped)<br />
            {<br />
                winmediaplayerstart();<br />
            }





我也不知道看看'folderpesni'的定义,所以期待该行的异常。为什么你将.URL属性用于非相关的url文件?



关于你在上面尝试使用的播放状态和其他方法;都不正确。



关于错误3的引用问题,我只能断定你的代码已经损坏了;也许在您的designer.cs文件中。尝试清理您的解决方案并再次构建它。 (如果这不起作用,请删除该组件并通过将其拖到表单中重新添加它。)您可能还必须替换它可能在代码中删除的处理程序。



我还强烈建议您在继续之前阅读有关此组件的文档。 文档



如果您有任何疑问,请告诉我。



I also don't see where ' folderpesni ' Is defined, so expect an exception on that line. And why are you using the .URL property for a non related url file?

Regarding your playstate and other methods you are trying to use above; are all incorrect.

About the referencing issue on Error 3, I can only conclude you have corrupted your code somewhere; perhaps in your designer.cs file. Try to clean your solution and build it again. (If that does not work, remove the component and re-add it by dragging it to your form.) You may also have to replace the handlers which it may remove in code too.

I would also strongly recommend you to read the documentation on this component before going any further. Documentation.

If you have any questions, please let me know.


这篇关于Windows Media Player出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆