axiom-now-playing-carplay について
iOSアプリのCarPlayオーディオ対応を追加・診断する開発スキルです。既存の再生情報やリモートコマンドの再利用方法に加え、権限設定やテスト手順を説明します。
主な機能
- 01MPNowPlayingInfoCenterとMPRemoteCommandCenterの再利用
- 02CPNowPlayingTemplateのコントロール設定
- 03CarPlayオーディオ権限要件の確認
- 04メタデータ、アートワーク、ボタンの問題診断
- 05CarPlayシミュレーターでのテスト
活用シーン
- 01既存のオーディオアプリへのCarPlay対応追加
- 02Now Playingのメタデータやアートワークの欠落調査
- 03CarPlay上の再生コントロール確認
- 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.nowPlayingInfo | CPNowPlayingTemplate のメタデータ(タイトル、アーティスト、アートワーク) |
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 以降):
- 「I/O」→「外部ディスプレイ」→「CarPlay」
- CarPlay ディスプレイをタップ
- 「オーディオ」セクションでアプリを探す
- 重要:確実にテストするには、デバッガーを使わずに実行してください(デバッガーが CarPlay のオーディオセッションの有効化を妨げることがあります)
実車:
Apple によるエンタイトルメントの承認が必要です(UIBackgroundModes に audio を設定したアプリは自動的に承認されるため、手動での申請は不要です)。
確認項目
- アプリが CarPlay の「オーディオ」セクションに表示される
- 「再生中」に正しいメタデータが表示される
- アルバムアートが表示される
- 再生/一時停止/スキップボタンが反応する
- カスタムボタンがある場合、表示されて動作する
- デバッガーを接続した場合と接続していない場合の両方でテストした
リソース
スキル:axiom-now-playing、axiom-now-playing-musickit
コメント
Markdown 対応