iOS中音乐锁屏控制音乐的示例分析-创新互联

这篇文章将为大家详细讲解有关iOS中音乐锁屏控制音乐的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

创新新互联,凭借10多年的成都做网站、网站设计、外贸营销网站建设经验,本着真心·诚心服务的企业理念服务于成都中小企业设计网站有1000多家案例。做网站建设,选创新互联。

具体代码如下所示:

 <pre name="code" class="objc">appDelegate里面加入如下代码获取后台播放权限</pre><pre name="code" class="objc">- (void)setAudioBackstagePlay{ 
  AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 
  [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil]; 
  [audioSession setActive:YES error:nil]; 
}</pre> 
<pre></pre> 
<pre name="code" class="objc">//重写父类方法,接受外部事件的处理 
- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent { 
  NSLog(@"remote"); 
  if (receivedEvent.type == UIEventTypeRemoteControl) { 
    switch (receivedEvent.subtype) { // 得到事件类型 
      case UIEventSubtypeRemoteControlTogglePlayPause: // 暂停 ios6 
        [_player musicPause]; // 调用你所在项目的暂停按钮的响应方法 下面的也是如此 
        break; 
      case UIEventSubtypeRemoteControlPreviousTrack: // 上一首 
        [self lastMusic]; 
        break; 
      case UIEventSubtypeRemoteControlNextTrack: // 下一首 
        [self nextMusic]; 
        break; 
      case UIEventSubtypeRemoteControlPlay: //播放 
        [_player musicPlay]; 
        break; 
      case UIEventSubtypeRemoteControlPause: // 暂停 ios7 
        [_player musicPause]; 
        break; 
      default: 
        break; 
    } 
  } 
}</pre><pre name="code" class="objc"><pre name="code" class="objc">- (void)configNowPlayingCenter { 
  NSLog(@"锁屏设置"); 
//   BASE_INFO_FUN(@"配置NowPlayingCenter"); 
  YBVideoListModel * list = _model.audioList[_currentIndexPath.row];</pre><pre name="code" class="objc"><span >  </span>//以下代码是加载锁屏显示网络图片以及其他设置 
  [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:list.thumbUrl] options:SDWebImageRetryFailed progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 
    if (image == nil) { 
      image = [UIImage imageNamed:@"default_music"]; 
    } 
    NSMutableDictionary * info = [NSMutableDictionary dictionary]; 
    //音乐的标题 
    [info setObject:list.title forKey:MPMediaItemPropertyTitle]; 
    //音乐的艺术家 
    NSString *author= list.singer; 
    [info setObject:author forKey:MPMediaItemPropertyArtist]; 
    //音乐的播放时间 
    [info setObject:@(_player.player.currentTime.value) forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]; 
    //音乐的播放速度 
    [info setObject:@(1) forKey:MPNowPlayingInfoPropertyPlaybackRate]; 
    //音乐的总时间 
    [info setObject:@(list.duration) forKey:MPMediaItemPropertyPlaybackDuration]; 
    //音乐的封面 
    MPMediaItemArtwork * artwork = [[MPMediaItemArtwork alloc] initWithImage:image]; 
    [info setObject:artwork forKey:MPMediaItemPropertyArtwork]; 
    //完成设置 
    [[MPNowPlayingInfoCenter defaultCenter]setNowPlayingInfo:info]; 
  }]; 
}</pre><br> 
<br> 
<pre></pre> 
<br> 
</pre>

关于“iOS中音乐锁屏控制音乐的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

本文名称:iOS中音乐锁屏控制音乐的示例分析-创新互联
本文来源:https://www.cdcxhl.com/article18/iddgp.html

成都网站建设公司_创新互联,为您提供网站维护网站设计公司云服务器定制开发外贸网站建设域名注册

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设公司