不停地播放视频 (Swift)
Playing a video without stopping (Swift)
我想在我的 swift 应用程序上播放 10-20 秒的视频,但有时由于网速较慢,它会停止并且不会再次加载,直到我暂停并播放。所以我想做的是在流式传输之前,下载完整的视频,这样它就不会再次停在中间。这是我正在使用的代码
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)
这就是我做的,添加了一个观察者来查找是否正在下载
NSNotificationCenter.defaultCenter().addObserver(self, selector: "videoStopped:", name: MPMoviePlayerLoadStateDidChangeNotification, object: moviePlayer)
使用 moviePlayer.currentPlaybackTime 和 moviePlayer.playableDuration
处理 videoStopped 函数 中的播放
我想在我的 swift 应用程序上播放 10-20 秒的视频,但有时由于网速较慢,它会停止并且不会再次加载,直到我暂停并播放。所以我想做的是在流式传输之前,下载完整的视频,这样它就不会再次停在中间。这是我正在使用的代码
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)
这就是我做的,添加了一个观察者来查找是否正在下载
NSNotificationCenter.defaultCenter().addObserver(self, selector: "videoStopped:", name: MPMoviePlayerLoadStateDidChangeNotification, object: moviePlayer)
使用 moviePlayer.currentPlaybackTime 和 moviePlayer.playableDuration
处理 videoStopped 函数 中的播放