相关疑难解决方法(0)

使用AVFoundation AVPlayer循环播放视频?

在AVFoundation中有一种相对简单的循环视频方式吗?

我已经创建了我的AVPlayer和AVPlayerLayer:

avPlayer = [[AVPlayer playerWithURL:videoUrl] retain];
avPlayerLayer = [[AVPlayerLayer playerLayerWithPlayer:avPlayer] retain];

avPlayerLayer.frame = contentView.layer.bounds;
[contentView.layer addSublayer: avPlayerLayer];
Run Code Online (Sandbox Code Playgroud)

然后我播放我的视频:

[avPlayer play];
Run Code Online (Sandbox Code Playgroud)

视频播放正常但最后停止播放.使用MPMoviePlayerController,您只需将其repeatMode属性设置为正确的值即可.AVPlayer似乎没有类似的属性.似乎没有一个回调可以告诉我什么时候电影结束所以我可以寻找开头并再次播放它.

我没有使用MPMoviePlayerController,因为它有一些严重的限制.我希望能够一次播放多个视频流.

objective-c avfoundation ios avplayer swift

139
推荐指数
5
解决办法
8万
查看次数

使用AVPlayerLooper循环播放多个视频

我一直在尝试找出如何使用 循环播放多个视频AVPlayerLooper,但它们templateItem采用 type 参数AVPlayerItem而不是[AVPlayerItem]。我目前正在使用 anAVQueuePlayer来显示视频,但我需要循环播放它。

到目前为止,这是我的代码:

class MyVC: UIViewController {

     @IBOutlet weak var playerView: UIView!

     lazy var backgroundVideoPlayer = AVQueuePlayer()

     // View Controller related code (viewDidLoad, etc.) is taken out for brevity.

     private func loadBackgroundVideosRandomly() -> [AVPlayerItem] {
         let mainBundle = Bundle.main
         let movieURLs = [mainBundle.url(forResource: "Boop Burj Al Arab", withExtension: "mov"),
                          mainBundle.url(forResource: "Boop Dubai", withExtension: "mov"),
                          mainBundle.url(forResource: "Boop Dubai Clock", withExtension: "mov"),
                          mainBundle.url(forResource: "Boop Dubai Lake", withExtension: "mov")].shuffled()

         let …
Run Code Online (Sandbox Code Playgroud)

repeat avfoundation ios avqueueplayer swift

2
推荐指数
1
解决办法
3934
查看次数