在Swift中使用MPMoviePlayerController()播放MP4 [英] Play MP4 using MPMoviePlayerController() in Swift

查看:180
本文介绍了在Swift中使用MPMoviePlayerController()播放MP4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法终生想出一种方法来播放在UIViewController中占据整个背景的MP4.

I can't for the life of me figure out a way to play an MP4 that takes up the entire background in a UIViewController.

到目前为止,我有以下内容,甚至根本无法播放视频.

So far I have the following, which doesn't even play the video at all.

我可以确认bokeh.mp4视频是否存在,因为如果我将文件更改为其他内容,则会引发错误,提示它丢失.

I can confirm that the bokeh.mp4 video exists because if I change the file to something else then it throws an error that it's missing.

override func viewDidAppear(animated: Bool)  {
    let filePath = NSBundle.mainBundle().pathForResource("bokeh", ofType: "mp4")
    self.moviePlayerController.contentURL = NSURL(string: filePath)
    self.moviePlayerController.prepareToPlay()
    self.moviePlayerController.repeatMode = .One
    self.moviePlayerController.controlStyle = .Embedded
    self.view.addSubview(self.moviePlayerController.view)
}

我在控制台中收到一个错误:

I get an error in the console:

2014-06-22 21:22:42.347 MoviePlayer[26655:60b] _itemFailedToPlayToEnd: {
    kind = 1;
    new = 2;
    old = 0;
}

我还尝试添加一个占用整个屏幕的UIView并将播放器添加到该视图,但这是相同的问题.它不会开始播放.

I've also tried adding a UIView that takes up the entire screen and adding the player to that view, but it's the same problem. It doesn't start playing.

我正在尝试获得与Vine相同的效果,当您第一次加载在后台播放视频的应用程序时.

I'm trying to achieve the same effect that Vine has when you first load up the application where it has the video playing in the background.

推荐答案

这真是一味烦人:

我所做的只是改变:

self.moviePlayerController.contentURL = NSURL(string: filePath)

收件人:

self.moviePlayerController.contentURL = NSURL.fileURLWithPath(filePath)

这篇关于在Swift中使用MPMoviePlayerController()播放MP4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆