Click here to Skip to main content
15,881,863 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
C#
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();
}
Posted
Comments
Sergey Alexandrovich Kryukov 15-Oct-14 18:11pm    
Did you add the assembly references after seeing Error 1? :-)
—SA
Bojmaliev 15-Oct-14 18:13pm    
How to add that?
Sergey Alexandrovich Kryukov 15-Oct-14 18:31pm    
Solution Explorer, project node, "Add Reference"...
Look, you apparently don't understand references. If so, you should not do UI development and anything complex, until you learn at least the basics. (Sorry if I just misunderstood you.)
—SA
[no name] 16-Oct-14 12:02pm    
A manually added reference is not required if you are dragging the component onto the form Sergey.
Sergey Alexandrovich Kryukov 16-Oct-14 12:19pm    
We are talking about programming, not "dragging". It does not matter what you drag or click, the mechanism of referencing is the only thing which is important. After all, you can even add code to the text of the project file and reload it, this is not the essence of things...
—SA

1 solution

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 />
            }


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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900