how to show seek track duration on control center

前端 未结 4 1831
无人及你
无人及你 2020-12-24 09:07

How do i pass the song info such as song name and track duration to control center. Player plays music fine and the play and pause control works fine though.

Playin

4条回答
  •  再見小時候
    2020-12-24 10:02

    You are looking for this:

    - (IBAction)playButtonTouched:(id)sender {
    
       Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
    
        if (playingInfoCenter) {
    
    
            NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
    
    
            MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imagedNamed:@"AlbumArt"]];
    
            [songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle];
            [songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist];
            [songInfo setObject:@"Audio Album" forKey:MPMediaItemPropertyAlbumTitle];
            [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
            [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
    
    
        }
    }
    

提交回复
热议问题