I've got some problems with video on my app's background.
Here is my program code:
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.
}
}
After launching my program, the Music app is muted. How do I fix it?
And one more question: after returning to this screen from home screen, without closing the app, video stops. Where is the problem?