在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,因为它有一些严重的限制.我希望能够一次播放多个视频流.
VideoPlayer(player: AVPlayer(url: URL(fileURLWithPath: Bundle.main.path(forResource: "*****", ofType: "mp4")!)))
Run Code Online (Sandbox Code Playgroud)
如何隐藏视频播放器上的按钮。我希望视频能够不断重复。您可以通过导入 AVKit 库来访问 VideoPlayer 对象。
import AVKit
Run Code Online (Sandbox Code Playgroud)
嗨,大家好我有UIPageViewController和通知的问题.
我有一个带有一系列页面的页面UIPageVewController,所以在这些页面中我有一个循环播放的AV播放器如下:
func loopVideo(videoPlayer:AVPlayer){
NotificationCenter.default.addObserver(forName: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil, queue: nil){
[weak videoPlayer] notification in
videoPlayer?.seek(to: kCMTimeZero)
videoPlayer?.play()
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我使用滚动更改页面时,来自其他页面的通知会更改当前播放AVPlayer的视频.我在通知中放了一个打印件,我可以看到调用其他页面的通知.我不知道自己要做什么?
我尝试使用NotificationCenter.default.removeObserver(self)删除viewDidDisappear中的通知但是不起作用.
你能帮助我吗?
谢谢
我一直在尝试找出如何使用 循环播放多个视频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) ios ×3
swift ×3
avfoundation ×2
avplayer ×2
avkit ×1
mobile ×1
objective-c ×1
repeat ×1
swiftui ×1
video-player ×1
xcode ×1