我正在AVAudioPlayer中播放来自url的音频。我试图控制来自控制中心和锁定屏幕的音频。我可以控制搜索和前进,后退功能,但我无法控制控制中心的播放/暂停功能。
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
MPRemoteCommandCenter *remoteCommandCenter = [MPRemoteCommandCenter sharedCommandCenter];
[[remoteCommandCenter skipForwardCommand] addTarget:self action:@selector(skipForward)];
[[remoteCommandCenter togglePlayPauseCommand] addTarget:self action:@selector(togglePlayPause)];
[[remoteCommandCenter skipBackwardCommand] addTarget:self action:@selector(skipBackward)];
MPNowPlayingInfoCenter *playingInfoCenter = [MPNowPlayingInfoCenter defaultCenter];
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
[songInfo setObject:@"your song" forKey:MPMediaItemPropertyTitle];
[songInfo setObject:@"your artist" forKey:MPMediaItemPropertyArtist];
[songInfo setObject:@"your album" forKey:MPMediaItemPropertyAlbumTitle];
[songInfo setObject:@"0" forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
[songInfo setObject:@"600" forKey:MPMediaItemPropertyPlaybackDuration];
[playingInfoCenter setNowPlayingInfo:songInfo];