Display now playing information in Command Center

Previously, I covered an article Configure Audio Session for background audio mode (iOS Project). Next step is to show relevant information in Command Center for audio played from your iOS Application.

Let’s start by importing MediaPlayer

import MediaPlayer

Next, place the following code to set now playing information

let image = UIImage(named: "artwork")!
let mediaArtwork = MPMediaItemArtwork(boundsSize: image.size) { (size: CGSize) -> UIImage in
  return image
}

let nowPlayingInfo: [String: Any] = [
  MPMediaItemPropertyArtist: "hashaam.com",
  MPMediaItemPropertyTitle: "Live Streaming Example",
  MPMediaItemPropertyArtwork: mediaArtwork,
  MPNowPlayingInfoPropertyIsLiveStream: true
]

MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo  

Notice, setting the MPNowPlayingInfoPropertyIsLiveStream to true will show LIVE status in Command Center.

This gives required information to be displayed in Command Center
Display now playing information in Command Center

And also in the lock screen
Display now playing information in Lock Screen

Here is gist for the example

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s