gpt4 book ai didi

ios - MPMoviePlayerController 切换视频

转载 作者:行者123 更新时间:2023-11-30 14:08:36 25 4
gpt4 key购买 nike

我正在播放视频:

let path = NSBundle.mainBundle().pathForResource("Video", ofType:"mp4")
let url = NSURL.fileURLWithPath(path!)
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = self.view.bounds
player.prepareToPlay()
player.scalingMode = .AspectFill
player.controlStyle = .None
self.view.addSubview(player.view)
}

我想在按下按钮时将其替换为另一个视频:

@IBAction func aButtonIsPressed(sender: AnyObject) {
let path = NSBundle.mainBundle().pathForResource("Another Video", ofType:"mp4")
let url = NSURL.fileURLWithPath(path!)
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = self.view.bounds
player.prepareToPlay()
player.scalingMode = .AspectFill
player.controlStyle = .None
self.view.addSubview(player.view)
}
}

当我点击按钮时,视频会播放,但添加新视频似乎有延迟,这导致过渡不稳定。有什么办法可以最大程度地减少这种延迟吗?我可以尝试添加另一个 MPMoviePlayerController 来预加载第二个视频,但通过一些测试,我发现导致剪辑的行就在这里。

self.view.addSubview(player.view)

我可以一直播放第一个视频,直到出现“didFinish”上方的行吗?那太好了。

最佳答案

您正在创建新的 MPMoviePlayerController 对象,这就是您遇到此问题的原因,您应该使用相同的对象并且该对象已经在播放对象,只需将 contentURL 属性设置为 new资源的URL

If you set this property while a movie is playing, that movie pauses and the new movie begins loading. The new movie starts playing at the beginning

有关更多详细信息,请访问此 link

关于ios - MPMoviePlayerController 切换视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32035007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com