使用mpmovieplayercontroller ios无法获得实时视频的缓冲状态

时间:2015-01-09 12:32:22

标签: ios swift mpmovieplayercontroller

我正在使用MPmovieplayercontroller播放实时流媒体视频。我还可以显示视频播放的时间。我能够播放视频,但是当它获得缓冲并恢复其播放状态同时无法获得缓冲状态,因此定时器没有正确更新,而是跳了一段时间。有什么办法让它正常吗?请帮我解决。提前致谢

我的代码在这里: -

   NSNotificationCenter.defaultCenter().addObserver(self, selector: "moviePlayBackStateChanged:", name: "MPMoviePlayerLoadStateDidChangeNotification",object:  moviePlayer)
    if(moviePlayer?.playableDuration > 0)
                        {
                            currentTime = moviePlayer!.currentPlaybackTime
                        }
                        else
                        {
                            currentTime = 0
                        }
    func moviePlayBackStateChanged(notification:NSNotification)
        {
            if(moviePlayer?.loadState == MPMovieLoadState.Playable)
            {
                currentTime = moviePlayer!.currentPlaybackTime
                println("currentTime\(currentTime)")
                lblTime?.text = stringFromTimeInterval(currentTime!)          
            }else if(moviePlayer?.loadState == MPMovieLoadState.Stalled)
            {
                lblTime?.text = stringFromTimeInterval(currentTime!)
            }
}

0 个答案:

没有答案