您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页iOS播放器

iOS播放器

来源:伴沃教育

锁屏状态下显示专辑图片、信息、进度等等

Paste_Image.png
 Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
    
    if (playingInfoCenter) {
        NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
        UIImage *image = [UIImage imageNamed:@"image"];
        MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:image];
        //歌曲名称
        [songInfo setObject:@"深夜地下铁" forKey:MPMediaItemPropertyTitle];
        //演唱者
        [songInfo setObject:@"陶钰玉" forKey:MPMediaItemPropertyArtist];
        //专辑名
        [songInfo setObject:@"深夜地下铁" forKey:MPMediaItemPropertyAlbumTitle];
        //专辑缩略图
        [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
        [songInfo setObject:[NSNumber numberWithDouble:[audioY getCurrentAudioTime]] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]; //音乐当前已经播放时间
        [songInfo setObject:[NSNumber numberWithFloat:1.0] forKey:MPNowPlayingInfoPropertyPlaybackRate];//进度光标的速度 (这个随 自己的播放速率调整,我默认是原速播放)
        [songInfo setObject:[NSNumber numberWithDouble:[audioY getAudioDuration]] forKey:MPMediaItemPropertyPlaybackDuration];//歌曲总时间设置
        
        //        设置锁屏状态下屏幕显示音乐信息
        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
    }

过程中遇到一些问题
1.只添加MPMediaItemPropertyPlaybackDuration(歌曲总时间)
问题:不显示当前进度
解决:添加MPMediaItemPropertyPlaybackDuration同时也出现问题,剩余时间每次减2秒

2.添加了MPMediaItemPropertyPlaybackDuration和MPNowPlayingInfoPropertyElapsedPlaybackTime
问题:出现了剩余时间每次减2秒的情况
解决:要添加MPNowPlayingInfoPropertyPlaybackRate就可以

3.暂停恢复播放更新 锁屏进度条

 NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:[[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo]];
[dict setObject:[NSNumber numberWithDouble:audioPlayer.playableDuration] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]; //音乐当前已经过时间
 [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:dict];

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务