-2

Is it possible for my app to skip or pause the music that is currently being played while the device (iPhone) is locked (for example after a given preset time)?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Robin
  • 11

1 Answers1

0

To play some music

func playSpawnedDot() {
    var alertSound: NSURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("spawnDot", ofType: "mp3")!)!
    var error:NSError?
    audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)
    audioPlayer.prepareToPlay()

    if volumeBool {
        audioPlayer.play()
    }
}

And play while app is in background too add this

AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)

To stop the music after n seconds do have a look in background modes Background modes IOS

Jeesson_7
  • 761
  • 1
  • 11
  • 38