我试图通过MPMoviePlayerController在一个屏幕上播放两个视频,但每次只播放其中一个。 这是我的playVideo功能:
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)
}
答案 0 :(得分:3)
请参阅docs:
请注意
虽然您可以创建多个MPMoviePlayerController对象和 在您的界面中呈现他们的观点,一次只有一个电影播放器 可以播放它的电影。
如果您希望一次能播放两部电影,请查看AVPlayerLayer
和AVSynchronizedLayer