Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios MPMovieplayercontroller缓冲区状态和流时暂停_Ios_Video_Video Streaming_Mpmovieplayercontroller_Mpmovieplayer - Fatal编程技术网

Ios MPMovieplayercontroller缓冲区状态和流时暂停

Ios MPMovieplayercontroller缓冲区状态和流时暂停,ios,video,video-streaming,mpmovieplayercontroller,mpmovieplayer,Ios,Video,Video Streaming,Mpmovieplayercontroller,Mpmovieplayer,我正在制作一个视频播放应用程序,在我的服务器上播放视频。我通过以下代码启动应用程序 var url:NSURL = NSURL(string: "http://download1.mp4mobilemovies.net/Bollywood/Baahubali%20-%20The%20Beginning%20-%20DvdScr/Baahubali%20-%20The%20Beginning%20-%20DvdScr%20-%201.mp4")! self.moviePlayer

我正在制作一个视频播放应用程序,在我的服务器上播放视频。我通过以下代码启动应用程序

    var url:NSURL = NSURL(string: "http://download1.mp4mobilemovies.net/Bollywood/Baahubali%20-%20The%20Beginning%20-%20DvdScr/Baahubali%20-%20The%20Beginning%20-%20DvdScr%20-%201.mp4")!

    self.moviePlayer = MPMoviePlayerController()
    moviePlayer.movieSourceType = MPMovieSourceType.Streaming
    self.moviePlayer = MPMoviePlayerController(contentURL: url)
    self.moviePlayer.prepareToPlay()
    self.moviePlayer.shouldAutoplay = true
    self.moviePlayer.stop()
    self.moviePlayer.view.frame = self.view.frame
    self.view.addSubview(self.moviePlayer.view)
    self.moviePlayer.fullscreen = true
    self.moviePlayer.setFullscreen(true, animated: true)
    self.moviePlayer.controlStyle = MPMovieControlStyle.Embedded
    self.moviePlayer.scalingMode = MPMovieScalingMode.AspectFit
    self.moviePlayer.play()
甚至我有一个HUD,当视图出现时,它开始显示进度指示器,在那里我还设置了两个通知对象,以查看视频的playbackstate更改以及电影的加载状态。播放状态更改工作正常。视频开始播放,一段时间后进入暂停状态,加载状态不会变为暂停或未知,这样我就知道这是缓冲状态。请告知如何处理缓冲区状态和缓冲区完成时的自动播放

 NSNotificationCenter.defaultCenter().addObserver(self, selector: "videoCanPlay:", name: MPMoviePlayerLoadStateDidChangeNotification, object: nil)
 NSNotificationCenter.defaultCenter().addObserver(self, selector: "playbackchanged:", name:MPMoviePlayerPlaybackStateDidChangeNotification, object: nil)

func videoCanPlay(notification: NSNotification){
    var moviePlayerController = notification.object
        as! MPMoviePlayerController
    if(self.moviePlayer?.loadState == MPMovieLoadState.Playable)
    {
       // let value = UIInterfaceOrientation.LandscapeLeft.rawValue
       // UIDevice.currentDevice().setValue(value, forKey: "orientation")
      //  NSLog("Play");
        MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
    }
///这些状态不会被调用

    if(self.moviePlayer?.loadState == MPMovieLoadState.Stalled)
    {
        NSLog("stalled");
    }

     if (self.moviePlayer?.loadState == MPMovieLoadState.Unknown)
    {
        NSLog("unknown");
    }

}

您可以使用此方法检查播放机是否正在缓冲:

self.moviePlayer?.playableDuration

我没有测试答案,但我认为如果playableDuration为0,那么玩家当前正在缓冲

您可以使用此方法检查玩家是否正在缓冲:

self.moviePlayer?.playableDuration
我没有测试答案,但我认为如果playableDuration为0,那么玩家当前正在缓冲