i have made a function in iOS 8 to play a movie in the background and now when i want to use it in iOS 9 it gives me a warning and says that it best not to use MPMoviePlayer and instead use AVPlayer. but i don't know anything about AVPlayer. how can i convert this to a proper function without warning that uses AVPlayer instead of MPMoviePlayer? heres the func :
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
}
AVPlayerViewController is a subclass of UIViewController. So instead of using a regular view controller create your custom movie player controller as follow:
Try like this:
To use it as a background you can do as follow:
works in ios 9
import UIKit import MediaPlayer class videoView:UIViewController {