재생목록 큐
이 플러그인의 설치 단계와 전체 마크다운 가이드가 포함된 설정 프롬프트를 복사하세요.
8.5 큐 API를 사용해 팟캐스트 플레이어, 플레이리스트, 가이드 세션을 구축하세요. 이 모든 API는 추가형(additive)입니다: 기존 preload, play, pause, 그리고 complete 플로우가 동일하게 유지됩니다.
소스 예제는 플러그인 저장소에도 있습니다: capacitor-native-audio (docs/PLAYLIST.md). 이 API들은 플러그인 8.5 릴리스와 함께 제공됩니다 capacitor-native-audio PR #353.
알림 및 진행 상태 설정
“알림 및 진행 상황 구성” 섹션configure() 옵션은 플랫폼에 따라 다릅니다. Web에서는 progressInterval 만 지원됩니다. 전달 시 showNotification 또는 backgroundPlayback 원인 configure() 거부됩니다.
import { NativeAudio } from '@capgo/capacitor-native-audio';
// Web: only progressInterval is supported in configure().await NativeAudio.configure({ progressInterval: 0.5 });
// iOS and Android: notification and background options.await NativeAudio.configure({ showNotification: true, backgroundPlayback: true, progressInterval: 0.5,});backgroundPlayback: true 앱이 백그라운드로 전환될 때 플러그인의 일시정지 또는 재개 로직을 건너뜁니다 Android iOS에서만. configure() 이 옵션을 읽지 않으므로 iOS에서는 의존하지 마세요. Android에서는 하지 마세요 포그라운드 서비스를 시작합니다. 백그라운드 재생에 의존하기 전에 매니페스트 권한(FOREGROUND_SERVICE, FOREGROUND_SERVICE_MEDIA_PLAYBACK, WAKE_LOCK)과 자체 미디어 포그라운드 서비스가 필요합니다. 시작하기 믹싱 트레이드오프 및 알림 설정을 참조하세요.
iOS에서는, showNotification: true 오디오 세션을 전환하여 Now Playing이 Control Center와 잠금 화면에 표시되도록 합니다.
잠금 화면 및 알림의 다음/이전 건너뛰기는 다음에서 처리됩니다: iOS 및 Android 할 때 showNotification 부분 전사 업데이트를 수신합니다.
await NativeAudio.addListener('queueChange', ({ assetId, index, reason }) => { console.log('queue', assetId, index, reason);});
await NativeAudio.addListener('progress', ({ assetId, position, duration }) => { console.log(assetId, position, duration);});
await NativeAudio.addListener('playbackState', (state) => { console.log(state.assetId, state.state, state.reason, state.isPlaying, state.currentTime, state.duration);});| 이벤트 | 플랫폼 | 참고 사항 |
|---|---|---|
queueChange | iOS, Android, Web | 활성 큐 항목이 변경될 때 발생하며, 여기에는 setQueue 포함 autoPlay: true Web 및 네이티브(reason setQueue)도 포함됩니다. 또한 next, previous, select, 그리고 remoteNext. |
progress | iOS, Android, Web | 에서 configure({ progressInterval })까지의 간격. 기본값 0.5초. 필드: assetId, position, duration. |
playbackState | iOS, Android, Web | 필드: assetId, state (playing, paused, stopped), reason, isPlaying, 선택 사항 currentTime 및 duration. 네이티브 환경에서 잠금 화면 및 알림의 전송(transport)을 포함합니다. Web에서는 플러그인의 전송 메서드가 재생 상태(재생, 일시정지, 재개, 반복, 완료)를 변경할 때 발생하며, 이는 네이티브 환경의 전송과 동일합니다. |
audioRouteChange | iOS, Android, Web | 성공적으로 setSpeaker 또는 setEarpiece 호출 시 라우트가 변경되지 않더라도 이벤트가 발생합니다. 헤드폰이나 Bluetooth가 단독으로 연결될 때는 발생하지 않습니다. Web에서는 setSpeaker emit함 route: 'speaker' 및 setEarpiece emit함 route: 'earpiece'. |
currentTime 재생 중 약 100ms마다 계속 발생합니다.
큐 빌드 및 시작
“큐 빌드 및 시작” 섹션setQueue 과 동일한 필드를 받습니다 preload 항목당 (assetId, assetPath, isUrl, volume, audioChannelNum, notificationMetadata, headers). 일치하는 id를 가진 사전 로드된 자산은 재사용됩니다. 옵션에는 다음도 포함됩니다 startIndex (기본값 0) 및 autoPlay (기본값 false). 반환 값은 QueueState 포함 assetId, index, count, 그리고 assetIds.
await NativeAudio.setQueue({ items: [ { assetId: 'ep-1', assetPath: 'https://example.com/ep1.mp3', isUrl: true, notificationMetadata: { title: 'Episode 1', artist: 'Show', artworkUrl: 'https://example.com/cover.png', }, }, { assetId: 'ep-2', assetPath: 'https://example.com/ep2.mp3', isUrl: true, notificationMetadata: { title: 'Episode 2', artist: 'Show', artworkUrl: 'https://example.com/cover.png', }, }, ], startIndex: 0, autoPlay: true,});큐 탐색
“큐 탐색” 섹션queueNext, queuePrevious, 그리고 queueSelect 재생 중인 항목을 중지하고 선택한 항목을 시작합니다. 각 메서드는 업데이트된 QueueState.
const state = await NativeAudio.getQueueState();console.log(state.assetId, state.index, state.count, state.assetIds);
await NativeAudio.queueNext();await NativeAudio.queuePrevious();await NativeAudio.queueSelect({ assetId: 'ep-2' });await NativeAudio.clearQueue();완료 후 진행 complete
“완료 후 진행” 섹션자동 진행은 앱 주도 방식이며, preload 및 play 모델과 동일합니다. 진행 전에 이벤트와 선택된 큐 에셋을 비교하세요. assetId 선택된 큐 에셋을 처리한 후 다음으로 진행합니다. queueNext() 선택된 항목을 이미 시작하므로, 이후에 호출하지 마세요. resume() Web에서는 이전 항목이 정지되기 전에 선택된 인덱스가 업데이트되므로, 이 가드는 iOS와 Android와 동일하게 작동합니다.
await NativeAudio.addListener('complete', async ({ assetId }) => { const { assetId: selectedId, index, count } = await NativeAudio.getQueueState(); if (assetId !== selectedId) { return; } if (index + 1 < count) { await NativeAudio.queueNext(); }});재생 스냅샷 및 속도
“재생 스냅샷 및 속도” 섹션getPlaybackState() 반환합니다 PlaybackStateEvent: assetId, state, reason, isPlaying, 그리고 선택 사항인 currentTime 및 duration. 에셋이 현재 재생 중이라면, state 이며 playing 트래킹 스냅샷이 오래되었더라도 라이브 요소에서 가져옵니다. 그렇지 않으면 state 해당 에셋의 마지막 playbackState 이벤트와 일치하는 트래킹 스냅샷을 사용합니다. 활성 에셋이 없으면 assetId 은(는) 비어 있습니다. getRate() 가 실제 assetId로만 호출되도록 가드하세요. play 은(는) 오디오 요소를 재생성하고 속도를 초기화하므로, 호출하세요 setRate 후 play.
const snapshot = await NativeAudio.getPlaybackState();console.log(snapshot.assetId, snapshot.state, snapshot.reason, snapshot.isPlaying, snapshot.currentTime, snapshot.duration);
if (snapshot.assetId) { const { rate } = await NativeAudio.getRate({ assetId: snapshot.assetId }); console.log(rate);}오디오 라우팅
“Audio routing” 섹션await NativeAudio.setSpeaker();await NativeAudio.setEarpiece();
const { route } = await NativeAudio.getAudioRoute();console.log(route);
await NativeAudio.addListener('audioRouteChange', ({ route }) => { console.log('route', route);});route 이며 speaker, earpiece, 또는 external. 성공 setSpeaker 및 setEarpiece 호출 시 emit audioRouteChange, 라우트가 변경되지 않아도 마찬가지입니다. 헤드폰이나 Bluetooth가 자체적으로 연결될 때는 이벤트가 발생하지 않습니다. Android의 경우 getAudioRoute 보고서에 따르면 earpiece 는 통신 모드에서만 setEarpiece; 그 외에는 speaker 헤드셋이나 Bluetooth가 연결되지 않은 경우. Web에서는 setSpeaker 및 setEarpiece no-op이 아닙니다: setSpeaker emit함 audioRouteChange 포함 route: 'speaker', setEarpiece emit함 route: 'earpiece', 그리고 getAudioRoute 마지막으로 요청된 라우트를 반환합니다 (speaker 후 setSpeaker, earpiece 후 setEarpiece). Web 플랫폼은 실제 출력을 변경할 수 없습니다.
관련 항목
“관련 항목” 섹션- 개요
- 시작하기
- 플러그인 변경 이력 및 마이그레이션: capacitor-native-audio PR #353