【问题标题】:Multiple URL playing C# Windows Media Player多个 URL 播放 C# Windows Media Player
【发布时间】:2015-02-19 10:29:02
【问题描述】:

我一直在尝试在 C# 表单应用程序中制作电视,到目前为止一切正常,但我在这里寻求的是如何命令它在当前 URL 完成时播放下一个 URL .

如果它应该是电视,它不应该停止播放!我希望我的程序在用户选择特定频道时继续播放一堆 URL 而不是一个,直到用户切换到另一个频道然后它开始播放另一组 URL。

如果它在用户切换回之前的频道而不是在应该播放的 URL 列表中播放随机的新 URL 时恢复视频,那就太棒了。

【问题讨论】:

    标签: c# media television windows-media-player


    【解决方案1】:

    尝试连接一个 PlayStateChange 事件处理程序并使用它通过下一个 URL 重新启动播放器。这是我的一个程序中的几个sn-ps代码,它一遍又一遍地重复相同的URL,但原理应该是一样的。

      // 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();
            }
         }
      }
    

    不知道这是否也适用于您的应用程序,但也许。

    编辑: 只记得我不久前回答了一个类似的问题,并在那里发布了我的整个程序。 https://stackoverflow.com/a/27431791/253938

    【讨论】:

    • 非常感谢!我想知道您是否可以将您的程序的项目文件夹发送到electronic.ubi@gmail.com 我想仔细看看按钮和其他所有内容。如果可能的话
    • @SaberKowsari 抱歉,但这不太可能。我在这里和另一个问题上发布的内容是一个更大程序的一小部分。总共 250,000 行代码。但在我对另一个问题的回答中,我包含了一个指向我认为有一些示例代码的网页的链接。
    • 我明白了,好的!有没有其他更简单的方法来制作这样的程序。我听说过 Shockwave 闪光物体!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多