iOS Audio Player with Lock Screen Controls

audio_player_thumbPrior to iOS 7.1 the UIApplication’s beginReceivingRemoteControlEvents method needed to be called and remoteControlReceivedWithEvent implemented where you’d handle remote control events by the event type that is received. In iOS 7.1 MPRemoteCommandCenter is introduced. With command center it is much more convenient to handle the remote control events.

beginReceivingRemoteControlEvents method description:

Tells the app to begin receiving remote-control events.
In iOS 7.1 and later, use the shared MPRemoteCommandCenter object to register for remote control events. You do not need to call this method when using the shared command center object.

The MPRemoteCommandCenter shared instance should be used to handle remote control events sent by external accessories and system transport controls. For each type of remote control event (e.g. play, pause, etc.), there is a MPRemoteCommand object property (playCommand, pauseCommand, etc.). To respond to those events you simply register a handler with that appropriate MPRemoteCommand object.

MPNowPlayingInfoCenter is used to display additional information regarding a currently playing track.

To find out more check out the sample audio player application with lock screen controls written in Swift that is available on my GitHub repo: https://github.com/lukagabric/LGAudioPlayerLockScreen

  • IMG_2937_1
  • IMG_2937_3
  • IMG_2937_2
  • IMG_2937_4

 

If you liked this blog post I’d appreciate if you followed me on Twitter

Related Post

Remember to share...Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someone

7 thoughts on “iOS Audio Player with Lock Screen Controls

  1. Thanks Thanks

    This is a great app

    but I need work with storyboard for work in iphone and ipad

    I rewrite this app
    in new project with storyboard

    but when run app erorr here
    required init?(coder aDecoder: NSCoder) {
    fatalError(“init(coder:) has not been implemented”)
    }

    why
    please help me

    Thanks

  2. Hi Luka,

    I’m a huge fan of your blog and website – really great stuff, thanks for sharing!

    Quick question about LGAudioPlayerLockScreen project. The audio files that I’m trying to play are significantly larger than your demo files, so I’d like to not house them in the app. Do you know of a simple way in PlaylistViewController.swift to point it towards a URL or remote server instead of including the audio files in the actual Xcode project? As an example, a URL that I plan on using is http://marc.ucla.edu/mpeg/01_Breathing_Meditation.mp3. Any ideas would be greatly appreciated!

Leave a Reply

Your email address will not be published. Required fields are marked *