我在应用的背景上遇到了一些视频问题。
这是我的程序代码:
import UIKit
import AVKit
import AVFoundation
class IntroViewController: UIViewController {
var player: AVPlayer?
override func viewDidLoad() {
super.viewDidLoad()
let videoURL: NSURL = NSBundle.mainBundle().URLForResource("intro", withExtension: "mov")!
player = AVPlayer(URL: videoURL)
player?.actionAtItemEnd = .None
player?.muted = false
let playerLayer = AVPlayerLayer(player: player)
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
playerLayer.zPosition = -1
playerLayer.frame = view.frame
view.layer.addSublayer(playerLayer)
player?.play()
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "loopVideo",
name: AVPlayerItemDidPlayToEndTimeNotification,
object: nil)
}
func loopVideo() {
player?.seekToTime(kCMTimeZero)
player?.play()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
启动我的程序后,音乐应用程序静音。我该如何解决?
还有一个问题:从主屏幕返回此屏幕后,如果没有关闭应用程序,视频会停止。问题在哪里?