1

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;
                                                      }
                                                  }];
}
4

1 に答える 1

1

解決

これに対する解決策は、アプリに入る UIEvents を監視し、ここから独自の通知を作成することでした。

関連するイベント タイプは次のとおりです。

UIEventTypeRemoteControl

関連するイベントのサブタイプは次のとおりです。

UIEventSubtypeRemoteControlPlay                 = 100,
UIEventSubtypeRemoteControlPause                = 101,
UIEventSubtypeRemoteControlStop                 = 102,
UIEventSubtypeRemoteControlTogglePlayPause      = 103,
UIEventSubtypeRemoteControlNextTrack            = 104,
UIEventSubtypeRemoteControlPreviousTrack        = 105,
UIEventSubtypeRemoteControlBeginSeekingBackward = 106,
UIEventSubtypeRemoteControlEndSeekingBackward   = 107,
UIEventSubtypeRemoteControlBeginSeekingForward  = 108,
UIEventSubtypeRemoteControlEndSeekingForward    = 109,
于 2014-03-18T04:33:46.810 に答える