Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

ios - How to set an title of the currently playing audio in iPhone lock screen?

When you play a music, the music title is shown below the time in the lock screen.

I have also seen how TuneIn radio does that by showing the name of the currently playing radio station.

How do you do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Read the documentation: MPNowPlayingInfoCenter

And here is an example code that will work on iOS 5 and it will not crash on older versions of iOS.

Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

if (playingInfoCenter) {
    MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
    NSDictionary *songInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                             @"Some artist", MPMediaItemPropertyArtist,
                             @"Some title", MPMediaItemPropertyTitle,
                             @"Some Album", MPMediaItemPropertyAlbumTitle,
                             nil];
    center.nowPlayingInfo = songInfo;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...