@@ -58,9 +58,8 @@ let playbackClaimId = 0;
5858let playbackOwner : AudioEngine | null = null ;
5959
6060function shouldUseNativeAudio ( ) : boolean {
61- // Native audio playback is disabled on macOS/Linux because the backend
62- // download path (getStreamData) can fail with 403 errors. The iframe-based
63- // YouTube player is more reliable across all platforms.
61+ // The maintained playback path is the YouTube iframe player. Native audio is
62+ // kept as an explicit fallback for player errors that are specific to a webview.
6463 return false ;
6564}
6665
@@ -141,6 +140,7 @@ export class AudioEngine {
141140 }
142141
143142 const requestId = ++ this . loadRequestId ;
143+ this . releaseNativeAudio ( ) ;
144144 const player = await this . ensurePlayer ( ) ;
145145 if ( requestId !== this . loadRequestId ) return ;
146146 if ( this . currentVideoId === videoId ) return ;
@@ -155,18 +155,34 @@ export class AudioEngine {
155155 videoId ,
156156 ) ;
157157 player . cueVideoById ( videoId ) ;
158- await cued ;
158+ try {
159+ await cued ;
160+ } catch ( error ) {
161+ if ( requestId === this . loadRequestId && this . currentVideoId === videoId ) {
162+ this . currentVideoId = null ;
163+ }
164+ throw error ;
165+ }
159166 if ( requestId !== this . loadRequestId || this . currentVideoId !== videoId ) return ;
160167 logInternalInfo ( "AudioEngine.loadTrack cued" , { videoId } ) ;
161168 }
162169
170+ async loadNativeFallback (
171+ videoId : string ,
172+ audioData : ArrayBuffer ,
173+ mimeType ?: string ,
174+ ) : Promise < void > {
175+ this . player ?. stopVideo ( ) ;
176+ await this . loadNativeAudio ( videoId , audioData , mimeType ) ;
177+ }
178+
163179 setOnEnded ( listener : ( ( ) => void ) | null ) : void {
164180 this . onEnded = listener ;
165181 }
166182
167183 async play ( ) : Promise < boolean > {
168184 const claimId = this . claimPlayback ( ) ;
169- if ( this . useNativeAudio ) {
185+ if ( this . useNativeAudio || this . audio ) {
170186 if ( ! this . audio || ! this . currentVideoId ) {
171187 throw new Error ( "No audio track is loaded." ) ;
172188 }
@@ -401,6 +417,7 @@ export class AudioEngine {
401417 }
402418
403419 private pauseForPlaybackClaim ( ) : void {
420+ this . audio ?. pause ( ) ;
404421 this . player ?. pauseVideo ( ) ;
405422 }
406423
0 commit comments