how to show seek track duration on control center

前端 未结 4 1835
无人及你
无人及你 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 09:46

    Are you playing songs from iPods music library ? If yes than You should you MPMusicPlayerViewController, it provides in-build functionality for seek bar properties as well as Info center.

    I can see here in your code you have used AVAudioPlayer, We can set only below details using AVAudioPlayer class, but can't access seekbar change event in our app.

    NSMutableDictionary *albumInfo = [[NSMutableDictionary alloc] init];
    UIImage *artWork = [UIImage imageNamed:album.imageUrl];
    [albumInfo setObject:album.title forKey:MPMediaItemPropertyTitle];
    [albumInfo setObject:album.auther forKey:MPMediaItemPropertyArtist];
    [albumInfo setObject:album.title forKey:MPMediaItemPropertyAlbumTitle];
    [albumInfo setObject:artworkP forKey:MPMediaItemPropertyArtwork];
    [albumInfo setObject:album.playrDur forKey:MPMediaItemPropertyPlaybackDuration]
    [albumInfo setObject:album.elapsedTime forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]
    [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:albumInfo]
    

    Here we need to count album.playrDur and album.elapsedTime as per required format.

提交回复
热议问题