如何同时播放2个视频?
How to play 2 video at the same time?
我正在尝试通过 MPMoviePlayerController 在一个屏幕上播放两个视频,但每次只播放其中一个。
这是我的播放视频功能:
func playVideo() {
let url = NSURL(string: videoUrls[videoNumber])
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = CGRect(x: 0, y: 200, width: 200, height: 200)
player.shouldAutoplay = true
player.prepareToPlay()
player.scalingMode = .AspectFill
player.controlStyle = .None
player.allowsAirPlay = false
self.view.addSubview(player.view)
}
let backUrl = NSURL(string: videoUrls[videoNumber+1])
backPlayer = MPMoviePlayerController(contentURL: backUrl)
if let player = backPlayer {
player.view.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
player.shouldAutoplay = true
player.prepareToPlay()
player.scalingMode = .AspectFill
player.controlStyle = .None
player.allowsAirPlay = false
self.view.addSubview(player.view)
}
参考docs:
Note
Although you can create multiple MPMoviePlayerController objects and
present their views in your interface, only one movie player at a time
can play its movie.
如果您希望同时播放两部电影,请查看 AVPlayerLayer
和 AVSynchronizedLayer
我正在尝试通过 MPMoviePlayerController 在一个屏幕上播放两个视频,但每次只播放其中一个。 这是我的播放视频功能:
func playVideo() {
let url = NSURL(string: videoUrls[videoNumber])
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = CGRect(x: 0, y: 200, width: 200, height: 200)
player.shouldAutoplay = true
player.prepareToPlay()
player.scalingMode = .AspectFill
player.controlStyle = .None
player.allowsAirPlay = false
self.view.addSubview(player.view)
}
let backUrl = NSURL(string: videoUrls[videoNumber+1])
backPlayer = MPMoviePlayerController(contentURL: backUrl)
if let player = backPlayer {
player.view.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
player.shouldAutoplay = true
player.prepareToPlay()
player.scalingMode = .AspectFill
player.controlStyle = .None
player.allowsAirPlay = false
self.view.addSubview(player.view)
}
参考docs:
Note
Although you can create multiple MPMoviePlayerController objects and present their views in your interface, only one movie player at a time can play its movie.
如果您希望同时播放两部电影,请查看 AVPlayerLayer
和 AVSynchronizedLayer