albumart= [[MPMediaItemArtwork alloc] initWithImage: img.image]; NSDictionary *playingNowInfo = @{MPMediaItemPropertyTitle: (self.currentItem.songname==nil) ? (@"") : (self.currentItem.songname),MPMediaItemPropertyPlaybackDuration: @(self.currentItem.duration),MPMediaItemPropertyArtist:[MusicSetting getArtistname],MPMediaItemPropertyAlbumTitle:(self.currentItem.albumname==nil) ? (@"") : (self.currentItem.albumname),MPNowPlayingInfoPropertyPlaybackRate: @(self.player.rate),MPNowPlayingInfoPropertyElapsedplaybackTime: @(CMTimeGetSeconds(self.player.currentItem.currentTime)),MPMediaItemPropertyArtwork:albumart,}; [MPNowPlayingInfoCenter defaultCenter].NowPlayingInfo = playingNowInfo;#pragma mark - Remote Control- (voID)remoteControlReceiveDWithEvent:(UIEvent *)receivedEvent { // [self.manager remoteControlReceiveDWithEvent:receivedEvent]; if (receivedEvent.type == UIEventTypeRemoteControl) { switch (receivedEvent.subtype) { case UIEventSubtypeRemoteControlPlay: [self Onclick_Play_Pause:self]; break; case UIEventSubtypeRemoteControlPause: [self Onclick_Play_Pause:self]; break; case UIEventSubtypeRemoteControlTogglePlayPause: //if ([self.manager.player isPlaying]) if(self.manager.player.rate != 0) { [self.manager.player pause]; } else { [self.manager.player play]; } break; case UIEventSubtypeRemoteControlNextTrack: [self Onclick_next:self]; NSLog(@"Next song play"); break; case UIEventSubtypeRemoteControlPrevIoUsTrack: [self Onclick_prev:self]; NSLog(@"Prev song play"); break; default: break; } }}- (IBAction)Onclick_Play_Pause:(ID)sender { (AppObj).playervIEw_height=playvIEwHeight; if(self.manager.player.rate != 0) { [MusicSetting set_SongStatus:@"Pause"]; [self.Play_PauseBtn setimage:[UIImage imagenamed:@"pauseimg"] forState:UIControlStatenormal]; [self.manager pause]; } else { [MusicSetting set_SongStatus:@"Play"]; [MusicSetting set_isMusicPlay:@"Playing"]; [self.Play_PauseBtn setimage:[UIImage imagenamed:@"playimg"] forState:UIControlStatenormal]; [self.manager play]; }}
谢谢!
解决方法- (IBAction)Onclick_Play_Pause:(ID)sender { MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter]; NSMutableDictionary *playingInfo = [NSMutableDictionary dictionaryWithDictionary:center.NowPlayingInfo]; (AppObj).playervIEw_height=playvIEwHeight; if(self.manager.player.rate != 0) { [MusicSetting set_SongStatus:@"Pause"]; [self.Play_PauseBtn setimage:[UIImage imagenamed:@"pauseimg"] forState:UIControlStatenormal]; [self.manager pause]; //set playback rate [playingInfo setobject:[NSNumber numberWithfloat:0] forKey:MPNowPlayingInfoPropertyPlaybackRate]; } else { [MusicSetting set_SongStatus:@"Play"]; [MusicSetting set_isMusicPlay:@"Playing"]; [self.Play_PauseBtn setimage:[UIImage imagenamed:@"playimg"] forState:UIControlStatenormal]; [self.manager play]; //set playback rate [playingInfo setobject:[NSNumber numberWithfloat:1] forKey:MPNowPlayingInfoPropertyPlaybackRate]; } center.NowPlayingInfo = playingInfo;}总结
以上是内存溢出为你收集整理的ios – MPNowPlayingInfoCenter播放暂停图像不会改变全部内容,希望文章能够帮你解决ios – MPNowPlayingInfoCenter播放暂停图像不会改变所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)