Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var player = AVPlayer()
- var playerViewController = AVPlayerViewController()
- override func viewDidLoad() {
- super.viewDidLoad()
- do {
- try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [.mixWithOthers, .allowAirPlay])
- print("Playback OK")
- UIApplication.shared.beginReceivingRemoteControlEvents()
- addPlayerNotifications()
- try AVAudioSession.sharedInstance().setActive(true)
- print("Session is Active")
- } catch {
- fatalError(error.localizedDescription)
- }
- }
- func addPlayerNotifications() {
- NotificationCenter.default.addObserver(self, selector: #selector(playerItemDidPlayToEnd), name: .AVPlayerItemDidPlayToEndTime, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(applicationWillEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
- }
Add Comment
Please, Sign In to add comment