更新时间:2023-12-05 15:40:34
不是使用-(void)remoteControlReceivedWithEvent:(UIEvent *)event
来跟踪控件,而是使用MPRemoteCommandCenter
将目标添加到每个控件中:
Instead of using -(void)remoteControlReceivedWithEvent:(UIEvent *)event
to track for the controls, use MPRemoteCommandCenter
adding targets to each one of the controls:
注意:在分配目标之前启用控件很重要.
Note: It's important to enable the controls before assigning a target.
[MPRemoteCommandCenter sharedCommandCenter].playCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].playCommand addTarget:self action:@selector(remotePlay)];
[MPRemoteCommandCenter sharedCommandCenter].pauseCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].pauseCommand addTarget:self action:@selector(remoteStop)];
[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].previousTrackCommand addTarget:self action:@selector(loadPreviousSong)];
[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand.enabled = YES;
[[MPRemoteCommandCenter sharedCommandCenter].nextTrackCommand addTarget:self action:@selector(loadNextSong)];
选择器:
-(void) remotePlay {
[APP_DELEGATE PlayPauseMusic:nil];
}
-(void) remoteStop {
[APP_DELEGATE PlayPauseMusic:nil];
}
-(void) loadNextSong {
[APP_DELEGATE next:nil];
}
-(void) loadPreviousSong {
[APP_DELEGATE previous:nil];
}