【发布时间】:2015-12-14 21:03:41
【问题描述】:
我在 iOS 8 中创建了一个在后台播放电影的功能,现在当我想在 iOS 9 中使用它时,它给了我一个警告,并说最好不要使用 MPMoviePlayer,而是使用 AVPlayer。但我对 AVPlayer 一无所知。我怎样才能将其转换为正确的函数而不发出警告使用 AVPlayer 而不是 MPMoviePlayer? 这是功能:
func playVideo() ->Bool {
let path = NSBundle.mainBundle().pathForResource("video", ofType:"mov")
//take path of video
let url = NSURL.fileURLWithPath(path!)
moviePlayer = MPMoviePlayerController(contentURL: url)
//asigning video to moviePlayer
if let player = moviePlayer {
player.view.frame = self.view.bounds
//setting the video size to the view size
player.controlStyle = MPMovieControlStyle.None
//Hiding the Player controls
player.prepareToPlay()
//Playing the video
player.repeatMode = .One
//Repeating the video
player.scalingMode = .AspectFill
//setting the aspect ratio of the player
self.view.addSubview(player.view)
self.view.addSubview(blurView)
self.view.sendSubviewToBack(blurView)
self.view.sendSubviewToBack(player.view)
//adding the player view to viewcontroller
return true
}
return false
}
【问题讨论】:
标签: ios swift avplayer ios9 mpmovieplayer