When Video plays using AVPLayer, it stops background music ios

Zalak Patel picture Zalak Patel · Apr 8, 2015 · Viewed 9.1k times · Source

I am playing video using AVPlayer, it stops iPhone's music which is on going in background. Please help me to resolve

let item1 = AVPlayerItem.init(URL: NSURL(string:path))
player = AVPlayer(playerItem: item1)
layer?.player = player;
player?.play()

Answer

Graham Perks picture Graham Perks · Aug 22, 2016

My movies are for animations; they have no sound. To let other sound continue playing, in Swift:

    // None of our movies should interrupt system music playback.
    _ = try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: .default, options: .mixWithOthers)

Thanks to Marcus Adams for the original answer.