Thomas K
Thomas K

Reputation: 184

AVPlayerViewController works in iOS8 but not in IOS7

I've been trying to get this to work for a while and i can't seem to figure out what the problem is. This code works fine on IOS8 but in IOS7 i get an error. I can see this error when i follow the debug navigator. In the debug area i only get an (lldb) error

Thread 1: EXC_BAD_ACCESS (code=1, address=0x10)

Here is my (on IOS8) working code of the videoViewController

import UIKit
import AVKit
import AVFoundation
import MediaPlayer

class VideoVC: UIViewController {
override func viewDidLoad() {
    super.viewDidLoad()

    var url:NSURL = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!
    let player = AVPlayer(URL: url)
    let playerController = AVPlayerViewController()

    playerController.player = player
    self.addChildViewController(playerController)
    self.view.addSubview(playerController.view)
    playerController.view.frame = self.view.frame

    player.play()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

Upvotes: 0

Views: 1186

Answers (1)

wyszo
wyszo

Reputation: 104

AVPlayerViewController has been introduced in iOS8 as part of AVKit. If you need to support earlier iOS versions, you need to use MPMediaPlayerViewController instead.

It’s disclosed in the documentation - notice availability section in AVPlayerViewController documentation page: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayerViewController_Class/

Also watch WWDC 2014 Session 513 if you’re curious about Media Playback: http://devstreaming.apple.com/videos/wwdc/2014/503xx50xm4n63qe/503/503_hd_mastering_modern_media_playback.mov?dl=1

Upvotes: 2

Related Questions