【问题标题】:MPMoviePlayerViewController stops playback when unplugging headphones拔下耳机时 MPMoviePlayerViewController 停止播放
【发布时间】:2010-10-19 09:22:25
【问题描述】:

我目前正在开发一个使用 MPMoviePlayerViewController 的网络电视应用程序。 MPMoviePlayer 在 iphone 上播放流媒体视频内容。

我遇到的问题是,一旦我拔下耳机(在看电视时),播放器就会停止。 由于我没有显示标准控件(上一个按钮、播放/暂停按钮、下一个按钮),而是我的自定义控件,因此除非切换到新频道,否则用户会被冻结的图片卡住..

有什么方法可以检测到因拔下耳机而导致的播放中断?

提前感谢您的提示和技巧,

山姆

【问题讨论】:

    标签: iphone mpmovieplayercontroller mpmovieplayer


    【解决方案1】:

    我没有直接回答你的问题。但我认为 MPMoviePlayerPlaybackStateDidChangeNotification 足以解决您的问题。收到通知后,从电影播放器​​对象的播放状态属性中获取播放状态并采取适当的措施。

    【讨论】:

      【解决方案2】:

      用一些代码详细说明接受的答案:

      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(videoPlaybackStateChanged:)
                                                   name:MPMoviePlayerPlaybackStateDidChangeNotification
                                                 object:moviePlayer];
      
      
      - (void)videoPlaybackStateChanged :(NSNotification *)notification
      {
          if (moviePlayer != nil && [moviePlayer playbackState] == MPMoviePlaybackStatePaused)
          {
              [moviePlayer play];
          }
      }
      

      【讨论】:

      • 值得注意的是,影片结尾处[moviePlayer playbackState] 更改为MPMoviePlaybackStatePaused。因此,如果您不希望电影重复播放,则需要使用[moviePlayer currentPlaybackTime] != [moviePlayer duration] 检查它是否位于结尾。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多