문제

I'm working on a radio app, which supports playing music in background. But i get stuck in how to set the title of music to remove control.

The difference between my app and "Music" is as following: Difference

What i should do to make my app display the title of a music like "Music" do?

Thanks!

도움이 되었습니까?

해결책

You can change the text of the now playing label by calling the MPNowPlayingInfoCenter, this will also allow you to modify the song name, album, artist, and album artwork on the lock screen.

#import <MediaPlayer/MPNowPlayingInfoCenter.h>
#import <MediaPlayer/MPMediaItem.h>

MPMediaItemArtwork *albumArt;


- (void)changeTrackTitles
{
  Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

    if (playingInfoCenter) 
    {
        albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imageNamed:@"HexagonArtwork"]];
        NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
        [songInfo setObject:@"SongName" forKey:MPMediaItemPropertyTitle];
        [songInfo setObject:@"AlbumName" forKey:MPMediaItemPropertyAlbumTitle];
        [songInfo setObject:@"ArtistName" forKey:MPMediaItemPropertyArtist];
        [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
    }
}

Code from: jaysonlane.net

다른 팁

Here's the example code:

#import <MediaPlayer/MPNowPlayingInfoCenter.h>
#import <MediaPlayer/MPMediaItem.h>

MPMediaItemArtwork *albumArt;


- (void)changeTrackTitles
{
  Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");

    if (playingInfoCenter) 
    {
        albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imageNamed:@"HexagonArtwork"]];
        NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
        [songInfo setObject:@"SongName" forKey:MPMediaItemPropertyTitle];
        [songInfo setObject:@"AlbumName" forKey:MPMediaItemPropertyAlbumTitle];
        [songInfo setObject:@"ArtistName" forKey:MPMediaItemPropertyArtist];
        [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top