How to set the title when playing music with remove control on iPhone?

前端 未结 2 2084
醉梦人生
醉梦人生 2020-12-30 18:18

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 m

2条回答
  •  Happy的楠姐
    2020-12-30 18:45

    Here's the example code:

    #import 
    #import 
    
    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];
        }
    }
    

提交回复
热议问题