Skill站外收录 @skilllib/skill-2117939930272415275
axiom-now-playing-carplay
通过统一的媒体控制中心实现 CarPlay 音频功能集成,自动同步播放信息与操作响应,支持自定义播放按钮及队列管理,需配置音频后台模式与专用权限以确保设备兼容性。
效率工具 AI 技能
Skills.MD
# CarPlay Integration
**Time cost**: 15-20 minutes (if MPNowPlayingInfoCenter already working)
## Key Insight
**CarPlay uses the SAME MPNowPlayingInfoCenter and MPRemoteCommandCenter as Lock Screen and Control Center.** If your Now Playing integration works on iOS, it automatically works in CarPlay with zero additional code.
## What CarPlay Reads
| iOS Component | CarPlay Display |
|---------------|-----------------|
| `MPNowPlayingInfoCenter.nowPlayingInfo` | CPNowPlayingTemplate metadata (title, artist, artwork) |
| `MPRemoteCommandCenter` handlers | CPNowPlayingTemplate button responses |
| Artwork from `nowPlayingInfo` | Album art in CarPlay UI |
No CarPlay-specific metadata needed. Your existing code works.
## CPNowPlayingTemplate Customization (iOS 14+)
For custom playback controls beyond standard play/pause/skip:
```swift
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)
}
}
```
## Entitlement Requirement
CarPlay requires an entitlement in your Xcode project:
**Info.plist:**
```xml
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
```
**Entitlements file:**
```xml
<key>com.apple.developer.carplay-audio</key>
<true/>
```
Without the entitlement, CarPlay won't show your app at all.
## CarPlay-Specific Gotchas
| Issue | Cause | Fix | Time |
|-------|-------|-----|------|
| CarPlay doesn't show app | Missing entitlement | Add `com.apple.developer.carplay-audio` | 5 min |
| Now Playing blank in CarPlay | MPNowPlayingInfoCenter not set | Same fix as Lock Screen (Pattern 1) | 10 min |
| Custom buttons don't appear | Configured after push | Configure at `templateApplicationScene(_:didConnect:)` | 5 min |
| Buttons work on device, not CarPlay simulator | Debugger interference | Test without debugger attached | 1 min |
| Album art missing | Same as iOS issue | Fix MPMediaItemArtwork (Pattern 3) | 15 min |
## Testing CarPlay
**Simulator (Xcode 12+):**
1. I/O → External Displays → CarPlay
2. Tap CarPlay display
3. Find your app in Audio section
4. **Important**: Run without debugger for reliable testing (debugger can interfere with CarPlay audio session activation)
**Real Vehicle:**
Requires entitlement approval from Apple (automatic for apps with `UIBackgroundModes` audio; no manual request needed).
## Verification
- [ ] App appears in CarPlay Audio section
- [ ] Now Playing shows correct metadata
- [ ] Album artwork displays
- [ ] Play/pause/skip buttons respond
- [ ] Custom buttons (if any) appear and work
- [ ] Tested both with and without debugger
## Resources
**Skills**: axiom-now-playing, axiom-now-playing-musickit
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「axiom-now-playing-carplay」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次