AVPlayer を使用してオーディオ (HLS) を再生するときに、iOS ControlCenter からの再生/一時停止イベントを処理する方法を探しています。
私はそれをすべて機能させていますが、ヘッダーファイルで公開されていない「名前付き」通知に基づいています。
これを行う「公式」の方法はありますか?
現在、次のコードが機能します。
- (void) removeControlCenterNotifications
{
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
}
- (void) addControlCenterNotifications
{
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
__weak MyClass *pWeakSelf = self;
__weak MoviePlayer *pWeakPlayer = player_;
[[NSNotificationCenter defaultCenter] addObserverForName:@"UIApplicationSimpleRemoteActionNotification"
object:nil
queue:NULL
usingBlock:^(NSNotification *notification)
{
if(pWeakSelf == nil) return;
NSNumber *type = notification.userInfo[@"UIApplicationSimpleRemoteActionType"];
switch ([type intValue]) {
case 6: [pWeakPlayer play]; break;
case 7: [pWeakPlayer pause]; break;
}
}];
}