Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When Video plays using AVPLayer, it stops background music ios

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()
like image 518
Zalak Patel Avatar asked Apr 08 '15 11:04

Zalak Patel


1 Answers

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.

like image 107
Graham Perks Avatar answered Dec 22 '22 08:12

Graham Perks