0

I've been trying to make a TV in the C# form application and everything has gone fine so far except but The thing I'm seeking here is that how to command it to play the next URL when the current one is finished.

If it's supposed to be a TV it should not stop playing! I want my program to, when the user chooses a specific channel keep continuously playing a bunch of URLs instead of one, until the user switches to another channel and then it begins playing another group of URLs.

And it would be super awesome if it resumes the video when the user switches back to a previous channel other than playing a random new URL among the URL list it is supposed to play.

double-beep
  • 5,031
  • 17
  • 33
  • 41

1 Answers1

0

Try hooking up a PlayStateChange event handler and use it to re-start the player with the next URL. Here are a couple of snippets of code from a program of mine that repeats the same URL over and over again, but the principle should be the same.

  // Reference to an Interop object for the COM object that interfaces with Microsoft Windows 
  //  Media Player
  private readonly WindowsMediaPlayer _windowsMediaPlayer = null;

  // Number of repeats left, negative = keep looping
  private int _repeatCount = -1;

...

    // Instantiate the Windows Media Player Interop object 
    _windowsMediaPlayer = new WindowsMediaPlayer();

    // Hook up a couple of event handlers
    _windowsMediaPlayer.MediaError += WindowsMediaPlayer_MediaError;
    _windowsMediaPlayer.PlayStateChange += WindowsMediaPlayer_PlayStateChange;

...

  /// <summary>
  /// Method to start the media player playing a file.
  /// </summary>
  /// <param name="fileName">complete file name</param>
  /// <param name="repeatCount">zero = repeat indefinitely, else number of times to repeat</param>
  [SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow", MessageId = "repeatCount-1")]
  public void PlayMediaFile(string fileName, int repeatCount)
  {
     if (_windowsMediaPlayer == null)
        return;

     _repeatCount = --repeatCount;  // Zero -> -1, 1 -> zero, etc.

     if (_windowsMediaPlayer.playState == WMPPlayState.wmppsPlaying)
        _windowsMediaPlayer.controls.stop();  // Probably unnecessary

     _windowsMediaPlayer.URL = fileName;
     _windowsMediaPlayer.controls.play();
  }

...

  /// <summary>
  /// Event-handler method called by Windows Media Player when the "state" of the media player 
  /// changes. This is used to repeat the playing of the media for the specified number of 
  /// times, or maybe for an indeterminate number of times.
  /// </summary>
  private void WindowsMediaPlayer_PlayStateChange(int newState)
  {
     if ((WMPPlayState)newState == WMPPlayState.wmppsStopped)
     {
        if (_repeatCount != 0)
        {
           _repeatCount--;
           _windowsMediaPlayer.controls.play();
        }
     }
  }

Don't know if this will also work for your application, but maybe.

EDIT: Just remembered that I answered a similar question a while back, and there I posted my entire program. https://stackoverflow.com/a/27431791/253938

Community
  • 1
  • 1
RenniePet
  • 11,420
  • 7
  • 80
  • 106
  • Thanks a lot! I was wondering if you could send me the project folder of your programs to [email protected] I wanna take a close look at buttons and everything else. if possible – Saber Kowsari Feb 19 '15 at 12:02
  • @SaberKowsari Sorry, but that's not really possible. What I've posted here and on the other question is a tiny, tiny part of a much larger program. 250,000 lines of code altogether. But in my answer on the other question I included a link to a web page where I think there's some sample code. – RenniePet Feb 19 '15 at 12:31
  • I see, ok! is there any other rather easier ways to make such programm. I have heard of Shockwave flash objects! – Saber Kowsari Feb 19 '15 at 12:44