mcpField
A
axiom-now-playing-carplay

axiom-now-playing-carplay

github.com/charleswiltgen開発1.2k164 回インストール今日更新
リポジトリ

axiom-now-playing-carplay について

iOSアプリのCarPlayオーディオ対応を追加・診断する開発スキルです。既存の再生情報やリモートコマンドの再利用方法に加え、権限設定やテスト手順を説明します。

主な機能

  1. 01MPNowPlayingInfoCenterとMPRemoteCommandCenterの再利用
  2. 02CPNowPlayingTemplateのコントロール設定
  3. 03CarPlayオーディオ権限要件の確認
  4. 04メタデータ、アートワーク、ボタンの問題診断
  5. 05CarPlayシミュレーターでのテスト

活用シーン

  1. 01既存のオーディオアプリへのCarPlay対応追加
  2. 02Now Playingのメタデータやアートワークの欠落調査
  3. 03CarPlay上の再生コントロール確認
  4. 04デバッガー接続の有無による動作の検証

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/charleswiltgen/axiom --skill axiom-now-playing-carplay

インストール後、Claude Code で/axiom-now-playing-carplayを入力して読み込まれたか確認します。

詳細

CarPlay との統合

所要時間:15~20 分(MPNowPlayingInfoCenter がすでに動作している場合)

重要なポイント

CarPlay はロック画面やコントロールセンターと同じ MPNowPlayingInfoCenter および MPRemoteCommandCenter を使用します。 iOS で「再生中」の連携が動作していれば、追加のコードなしで CarPlay でも自動的に動作します。

CarPlay が読み取る情報

iOS コンポーネントCarPlay の表示
MPNowPlayingInfoCenter.nowPlayingInfoCPNowPlayingTemplate のメタデータ(タイトル、アーティスト、アートワーク)
MPRemoteCommandCenter のハンドラーCPNowPlayingTemplate のボタン操作
nowPlayingInfo のアートワークCarPlay UI のアルバムアート

CarPlay 専用のメタデータは不要です。既存のコードがそのまま動作します。

CPNowPlayingTemplate のカスタマイズ(iOS 14 以降)

標準の再生/一時停止/スキップ以外のカスタム再生コントロールを使用する場合:

import CarPlay

@MainActor
class SceneDelegate: UIResponder, UIWindowSceneDelegate, CPTemplateApplicationSceneDelegate {

    func templateApplicationScene(
        _ templateApplicationScene: CPTemplateApplicationScene,
        didConnect interfaceController: CPInterfaceController
    ) {
        // ✅ Configure CPNowPlayingTemplate at connection time (not when pushed)
        let nowPlayingTemplate = CPNowPlayingTemplate.shared

        // Enable Album/Artist browsing (shows button that navigates to album/artist view in your app)
        nowPlayingTemplate.isAlbumArtistButtonEnabled = true

        // Enable Up Next queue (shows button that displays upcoming tracks)
        nowPlayingTemplate.isUpNextButtonEnabled = true

        // Add custom buttons (iOS 14+)
        setupCustomButtons(for: nowPlayingTemplate)
    }

    private func setupCustomButtons(for template: CPNowPlayingTemplate) {
        var buttons: [CPNowPlayingButton] = []

        // Playback rate button
        let rateButton = CPNowPlayingPlaybackRateButton { [weak self] button in
            self?.cyclePlaybackRate()
        }
        buttons.append(rateButton)

        // Shuffle button
        let shuffleButton = CPNowPlayingShuffleButton { [weak self] button in
            self?.toggleShuffle()
        }
        buttons.append(shuffleButton)

        // Repeat button
        let repeatButton = CPNowPlayingRepeatButton { [weak self] button in
            self?.cycleRepeatMode()
        }
        buttons.append(repeatButton)

        // Update template with custom buttons
        template.updateNowPlayingButtons(buttons)
    }
}

エンタイトルメントの要件

CarPlay を利用するには、Xcode プロジェクトにエンタイトルメントが必要です。

Info.plist:

<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
</array>

エンタイトルメントファイル:

<key>com.apple.developer.carplay-audio</key>
<true/>

エンタイトルメントがないと、CarPlay にアプリが表示されません。

CarPlay 固有の注意点

問題原因解決方法時間
CarPlay にアプリが表示されないエンタイトルメントがないcom.apple.developer.carplay-audio を追加5 分
CarPlay の「再生中」が空白MPNowPlayingInfoCenter が設定されていないロック画面と同じ方法で修正(パターン 1)10 分
カスタムボタンが表示されないプッシュ後に設定しているtemplateApplicationScene(_:didConnect:) で設定する5 分
デバイスではボタンが動作するが、CarPlay シミュレーターでは動作しないデバッガーの干渉デバッガーを接続せずにテストする1 分
アルバムアートが表示されないiOS の問題と同じMPMediaItemArtwork を修正する(パターン 3)15 分

CarPlay のテスト

シミュレーター(Xcode 12 以降):

  1. 「I/O」→「外部ディスプレイ」→「CarPlay」
  2. CarPlay ディスプレイをタップ
  3. 「オーディオ」セクションでアプリを探す
  4. 重要:確実にテストするには、デバッガーを使わずに実行してください(デバッガーが CarPlay のオーディオセッションの有効化を妨げることがあります)

実車: Apple によるエンタイトルメントの承認が必要です(UIBackgroundModes に audio を設定したアプリは自動的に承認されるため、手動での申請は不要です)。

確認項目

  • アプリが CarPlay の「オーディオ」セクションに表示される
  • 「再生中」に正しいメタデータが表示される
  • アルバムアートが表示される
  • 再生/一時停止/スキップボタンが反応する
  • カスタムボタンがある場合、表示されて動作する
  • デバッガーを接続した場合と接続していない場合の両方でテストした

リソース

スキル:axiom-now-playing、axiom-now-playing-musickit

コメント