Swift:AVPlayerViewController不会播放来自设备的视频

时间:2016-10-28 13:40:10

标签: ios swift avplayerviewcontroller

网址

// What prints below for selectedMedia.videoPath
file:///private/var/mobile/Containers/Data/Application/9A7E21B7-81E7-4F4A-97FB-019AB99A3407/tmp/trim.4B1C07A3-0139-4AC3-B6DE-EB90F8CF582D.MOV

CODE

// From UIPickerViewController didFinishPickingMediaWithInfo
// To Populate a media
media.videoPath = info[UIImagePickerControllerMediaURL] as? URL


// To Load Player
self.selectedMedia = self.media[indexPath.row]
if self.selectedMedia?.isVideo == true {
    let moviePlayer = AVPlayerViewController()
    moviePlayer.delegate = self
    print(self.selectedMedia!.videoPath!)
    let url = URL(fileURLWithPath: self.selectedMedia!.videoPath! )
    let player = AVPlayer(url: url)
    moviePlayer.player? = player

    self.present(moviePlayer, animated: true, completion: { 
        player.play()
    })
}
else {
    self.showMediaImage()
}

// Result of above code = AVPlayerViewController is displayed with no content.

问题

为什么视频没有播放?

0 个答案:

没有答案