2015-06-19 117 views
0

我试图在我的快速应用上播放10-20秒视频,但有时因为互联网速度慢,停止播放,直到我暂停并播放为止。所以我想要做的是在流媒体播放之前下载完整的视频,这样它就不会再次停留在中间。这是我使用的代码不停止播放视频(Swift)

moviePlayer = MPMoviePlayerController(contentURL: url) 
     moviePlayer.movieSourceType = MPMovieSourceType.File 
     moviePlayer.controlStyle = MPMovieControlStyle.None 
     moviePlayer.view.backgroundColor = UIColor.blueColor() 
     moviePlayer.scalingMode = MPMovieScalingMode.AspectFit 
     moviePlayer.repeatMode = MPMovieRepeatMode.None; 
     moviePlayer.allowsAirPlay = false 
     moviePlayer.shouldAutoplay = false 
     moviePlayer.backgroundView.backgroundColor = UIColor.whiteColor() 
     moviePlayer.view.frame = self.bounds 
     self.addSubview(moviePlayer.view) 

回答

1

这是我做的,添加了一个观察者发现,如果下载

NSNotificationCenter.defaultCenter().addObserver(self, selector: "videoStopped:", name: MPMoviePlayerLoadStateDidChangeNotification, object: moviePlayer) 

处理使用moviePlayer.currentPlaybackTime和moviePlayer在videoStopped功能播放.playableDuration

+0

完美!工作 – Ankit

+0

你可以给我这个代码。我面临同样的问题,在应用程序内流式传输电影。当互联网缓慢时,我的视频暂停,如何处理。 – Saty

+0

func videoStopped(notication:NSNotification){*在此再次播放*} – user528432