Como carregar MPMoviePlayerController contentUrl assíncrono ao carregar o modo de exibição?
Eu tento reproduzir um vídeo usando um MPMoviePlayerController. A configuração é: envio um novo ViewController, depois configuro a visualização e a instância do player de filme em viewDidLoad e, em seguida, uso um NSURLSession.sharedSession (). DataTaskWithURL () onde carrego o recurso REST do filme para fornecer a URL. No bloco de conclusão, defino o contentUrl da instância do player de filme como esse URL e digo play. No entanto, o quadro do filme permanece preto. Se eu definir o contentUrl codificado como url em viewDidLoad, viewWillAppear ou viewDidAppear, o filme será exibido. O errorLog e accessLog são nulos. Portanto, suponho que algo esteja errado com o carregamento e a atribuição assíncrona de URLs do contentUrl do filme.
Configuração: Swift, Xcode 6 beta, iOS 8.
Abaixo alguns trechos de código:
class PresentationsViewController {
override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
let presentationViewController = PresentationViewController(presentations[indexPath.row])
navigationController.pushViewController(presentationViewController, animated: true)
}
}
class PresentationViewController {
var presentation: Presentation?
var moviePlayer: MPMoviePlayerController?
convenience init(_ presentation: Presentation) {
self.init()
self.presentation = presentation
}
override func viewDidLoad() {
super.viewDidLoad()
moviePlayer = MPMoviePlayerController()
moviePlayer!.view.frame = CGRect(x: X, y: Y, width: W, height: H)
moviePlayer!.movieSourceType = MPMovieSourceType.Unknown
moviePlayer!.controlStyle = MPMovieControlStyle.Embedded
NSURLSession.sharedSession().dataTaskWithURL(presentation.url) { data, response, error in
// Some JSON parsing etc.
self.moviePlayer!.contentURL = presentation.videoUrl
self.moviePlayer!.prepareToPlay()
self.moviePlayer!.play()
}.resume()
view.addSubview(moviePlayer.view)
}
}