播放某些项目后,AVPlayer无法播放 [英] AVPlayer not able to play after playing some items

查看:99
本文介绍了播放某些项目后,AVPlayer无法播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个简单的游戏,需要向用户经常显示2个视频,这些视频在我的本地软件包中.我只想在ViewController上播放这些视频.我的代码是:

I am building one simple game where I need to display 2 videos to user frequently videos are in my bundle locally. I just want to play that videos on my viewcontroller. My code for that is :

let playerItem = AVPlayerItem(URL: NSURL.fileURLWithPath("\(vdoPath)")) //vdoPath will be random of that two local video files from bundle
let player = AVPlayer(playerItem: playerItem)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
playerViewController.view.backgroundColor = UIColor.clearColor()
playerViewController.showsPlaybackControls = false
playerViewController.view.frame = self.playerView.bounds
self.playerView.addSubview(playerViewController.view)
self.addChildViewController(playerViewController)
player.play() 

AVPlayer有时会播放视频,直到12-15次才遇到问题,但是当我继续播放更多AVPlayer时,无法播放,显示如下: 我的文件和路径没有问题,因为在获得该文件和路径之前,我已经能够演奏12至15次,就像我说的那样.请给我适当的解决方案和原因.

AVPlayer plays videos for sometimes like I am not facing issue till 12-15 times but when I continue to play more AVPlayer not able to play it showing like this: There is no issue with my file and path because before getting this I am able to play 12-15 times as I said. please give me proper solution and reason behind this.

推荐答案

您需要使用player.replacePlayerItem(item)而不是两次调用 如果仍然无法正常工作,请随时问我.首先,让AVPlayer播放第一个视频,然后等待控制器完成,然后再启动另一个视频.

You need to use player.replacePlayerItem(item) instead of twice calling if still not working ask me anytime. First let AVPlayer play first video then wait your controller till completion then start another.

这篇关于播放某些项目后,AVPlayer无法播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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