0
    private void mediaPlayer_Enter()
    {
        string path = Path.GetFullPath(currentTrack.Text);
        System.Diagnostics.Debug.WriteLine(path);
        mediaPlayer.URL = path;
        mediaPlayer.Ctlcontrols.play();
    }

This is the piece of code which is being called when the state of the media player turns to "media ended". I know that it does execute that line of code but it still doesn't play. It takes the item out of the listbox (which is the playlist) and loads it into the mediaPlayer but does not Automatically play the song. I have to press the button to start playing it - it has do play it stright away by itself. What am I doing wrong?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Maynn
  • 515
  • 1
  • 6
  • 10

2 Answers2

0

I believe this will autoplay your media: http://msdn.microsoft.com/en-us/library/windows/desktop/dd562405(v=vs.85).aspx

If the AxWindowsMediaPlayer.settings.autoStart property is true, playback begins automatically whenever you set currentMedia.

pennstatephil
  • 1,593
  • 3
  • 22
  • 43
  • private void mediaPlayer_Enter() { string path = Path.GetFullPath(currentTrack.Text); System.Diagnostics.Debug.WriteLine(path); mediaPlayer.mediaCollection.add(path); WMPLib.IWMPMedia3 song = (WMPLib.IWMPMedia3)mediaPlayer.mediaCollection.getAll().get_Item(0); mediaPlayer.currentMedia = song; mediaPlayer.Ctlcontrols.play(); } This is my current code. It works exactly the same as previously - loads the song but does not play it automatically. – Maynn Apr 09 '14 at 20:28
  • I don't see you setting autoStart to true anywhere in there. – pennstatephil Apr 09 '14 at 20:31
  • I've read that it is set to true by default. I will test whether it works when I state it anyway //edit - still doesnt work. – Maynn Apr 09 '14 at 20:32
  • My teacher explained it to me. There needs to be a small delay in between playing songs (so a short timer) to allow the player to clear the buffer. Otherwise - it doesnt have enough time to autoplay the loaded song. – Maynn Apr 11 '14 at 18:08
0

In the PlayStateChange Event or use your logic, the player must be ready for playing the file before we use the Play() command.

  private void WMPlayer1_PlayStateChange(object sender,AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)    
            {           
                if (WMPlayer1.playState == WMPPlayState.wmppsReady)
                    {
                        WMPlayer1.Ctlcontrols.play();         
                    }
            }
ouflak
  • 2,458
  • 10
  • 44
  • 49