MPNowPlayingInfoCenter – Control the music player in the Lock screen

Tram Ho

When you make a music player, you don’t want to always open the music app right from the home screen. Sometimes you will want to lock your phone just to listen to music, but you still want to control the music player like listening to the next track, previous track or a little bit of information …


Music is something that brings beauty in the form of a smile on a face. One of the most used and most trending apps is the music app. Each of us has one or another music app in our phone to help us relieve stress.


Now I will show you how to control music player on lock screen.

Necessary and sufficient conditions to apply in the application

To play music and get controls your iOS apps need the following:

  1. Media playback
  2. Remote commands configuration
  3. Playing info center configuration

1. Support playing music in background

For when the iOS app in the background can still play music, you need the following registration code:

Turn on Audio in Background Modes

2. Remote Commands

MPNowPlayingInfoCenter is a class that allows interaction between application and remote control at the lock screen. This class provides the MPRemoteCommand to handle in its application.

  • First register this Remote in the application using the following command


  • Handle functions you want

3. Playing info center configuration


There are also many other things you can handle through the MPRemoteCommandCenter such as seek, duration, elapsed, rate …

Hope this article can be of some help to you.


Share the news now

Source : Viblo