Swift AVPlayer不会播放器MP4:通过它播放按钮

时间:2015-12-23 02:21:44

标签: ios avfoundation avplayer avplayerviewcontroller

enter image description here

我正在尝试在ios应用上播放来自本地文件系统的mp4视频。视频大约一个小时,可以快速播放。如果是来自网络,我可以播放mp4(NSURL(字符串:“http:domain.com/vid.mp4”))。我正在播放如下视频:

    let steamingURL:NSURL = NSURL(string: video.filePath)! //valid path
    let player = AVPlayer(URL: steamingURL)
    player.allowsExternalPlayback = false

    PlayWorkoutViewController.playerController = AVPlayerViewController()
    PlayWorkoutViewController.playerController.player = player
    self.addChildViewController(PlayWorkoutViewController.playerController)
    self.view.addSubview(PlayWorkoutViewController.playerController.view)
    PlayWorkoutViewController.playerController.view.frame = videoContainerView.frame
    PlayWorkoutViewController.playerController.showsPlaybackControls = false
    player.play()

我是否需要更改部分设置才能播放较长的视频?感谢。

1 个答案:

答案 0 :(得分:7)

检查steamingURL是否为nil

如果你想使用NSURL(字符串:" xxx")初始化,请检查字符串以file://开头,否则使用NSURL(fileURLWithPath:" xxxx")。