Swift AVPlayer 无法播放 MP4:有线穿过的播放按钮

Swift AVPlayer Won't Player MP4: Play Button With Line Through It

我正在尝试在 ios 应用程序上播放来自本地文件系统的 mp4 视频。视频时长约一个小时,可以在 quicktime 上播放。如果来自网络 (NSURL(string: "http:domain.com/vid.mp4")),我可以播放 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()

我需要更改一些设置才能播放更长的视频吗?谢谢

先检查steamingURL是否为nil

如果您想使用 NSURL(string: "xxx") 初始化程序,请检查以 file:// 开头的字符串,否则使用 NSURL(fileURLWithPath: "xxxx") 代替。