我是新的 iOS 开发者。我正在尝试使正在播放栏(主屏幕底部栏)中的播放/暂停按钮模拟我的应用程序中的播放/暂停按钮。请提供任何帮助。
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
error:nil];
[[AVAudioSession sharedInstance] setActive:YES
error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self.player play];
UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
if([player play]){
newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^(void) {
[[UIApplication sharedApplication] endBackgroundTask: bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
//Your bg code here
[[UIApplication sharedApplication] endBackgroundTask: bgTask];
bgTask = UIBackgroundTaskInvalid;