@@ -78,12 +78,12 @@ export default class HLSSound extends BaseSound {
78
78
79
79
@waitFor
80
80
async setup ( ) {
81
- await this . loadHLS ( ) . then ( ( { HLS } ) => {
82
- let video = document . createElement ( 'video ') ;
83
- video . setAttribute ( 'crossorigin' , 'anonymous' ) ;
84
- this . video = video ;
85
-
86
- let options = { debug : false , startFragPrefetch : true } ;
81
+ if ( ! this . hls && ! this . video ) {
82
+ this . debug ( 'Setting up HLS ') ;
83
+ let options = {
84
+ debug : true ,
85
+ startFragPrefetch : true ,
86
+ } ;
87
87
88
88
if ( this . options ?. xhr ) {
89
89
options . xhrSetup = ( xhr , url ) => {
@@ -105,13 +105,29 @@ export default class HLSSound extends BaseSound {
105
105
delete this . options . xhr ;
106
106
}
107
107
108
- let hls = new HLS ( { ...options , ...( this . options || { } ) } ) ;
108
+ await this . loadHLS ( ) . then ( ( { HLS } ) => {
109
+ if ( this . hls ) {
110
+ this . hls . destroy ( ) ;
111
+ }
109
112
110
- this . hls = hls ;
111
- this . _setupHLSEvents ( hls , HLS ) ;
112
- this . _setupPlayerEvents ( video ) ;
113
- hls . attachMedia ( video ) ;
114
- } ) ;
113
+ if ( this . video ) {
114
+ this . video . removeAttribute ( 'src' ) ;
115
+ }
116
+
117
+ let hls = new HLS ( { ...options , ...( this . options || { } ) } ) ;
118
+ this . hls = hls ;
119
+
120
+ let video = document . createElement ( 'video' ) ;
121
+ video . setAttribute ( 'crossorigin' , 'anonymous' ) ;
122
+ video . setAttribute ( 'webkit-playsinline' , '' ) ;
123
+ video . setAttribute ( 'playsinline' , '' ) ;
124
+ this . video = video ;
125
+
126
+ this . _setupHLSEvents ( hls , HLS ) ;
127
+ this . _setupPlayerEvents ( this . video ) ;
128
+ hls . attachMedia ( this . video ) ;
129
+ } ) ;
130
+ }
115
131
}
116
132
117
133
_setupHLSEvents ( instance , HLS ) {
@@ -133,35 +149,33 @@ export default class HLSSound extends BaseSound {
133
149
instance . on ( HLS . Events . ERROR , ( e , data ) => this . _onHLSError ( e , data , HLS ) ) ;
134
150
135
151
instance . on ( HLS . Events . MEDIA_ATTACHED , ( ) => {
136
- this . debug ( 'media attached' ) ;
152
+ this . debug ( 'media attached, loading source ' ) ;
137
153
instance . loadSource ( this . url ) ;
154
+ } ) ;
138
155
139
- instance . on ( HLS . Events . MANIFEST_PARSED , ( e , data ) => {
140
- this . debug (
141
- `manifest parsed and loaded, found ${ data . levels . length } quality level(s)`
142
- ) ;
143
- this . manifest = data ;
144
- } ) ;
156
+ instance . on ( HLS . Events . MANIFEST_PARSED , ( e , data ) => {
157
+ this . debug (
158
+ `manifest parsed and loaded, found ${ data . levels . length } quality level(s)`
159
+ ) ;
160
+ this . manifest = data ;
161
+ } ) ;
145
162
146
- instance . on ( HLS . Events . LEVEL_LOADED , ( e , data ) => {
147
- this . debug ( `level ${ data . level } loaded` ) ;
148
- this . live = data . details . live ;
149
- this . _signalAudioIsReady ( ) ;
150
- } ) ;
163
+ instance . on ( HLS . Events . LEVEL_LOADED , ( e , data ) => {
164
+ this . debug ( `level ${ data . level } loaded` ) ;
165
+ this . live = data . details . live ;
166
+ this . _signalAudioIsReady ( ) ;
167
+ } ) ;
151
168
152
- instance . on ( HLS . Events . AUDIO_TRACK_LOADED , ( ) => {
153
- this . debug ( 'audio track loaded' ) ;
154
- this . _signalAudioIsReady ( ) ;
155
- } ) ;
169
+ instance . on ( HLS . Events . AUDIO_TRACK_LOADED , ( ) => {
170
+ this . debug ( 'audio track loaded' ) ;
171
+ this . _signalAudioIsReady ( ) ;
172
+ } ) ;
156
173
157
- instance . on ( HLS . Events . ERROR , ( e , data ) =>
158
- this . _onHLSError ( e , data , HLS )
159
- ) ;
174
+ instance . on ( HLS . Events . ERROR , ( e , data ) => this . _onHLSError ( e , data , HLS ) ) ;
160
175
161
- instance . on ( HLS . Events . FRAG_CHANGED , ( e , f ) => {
162
- // this._updateAudioBuffer(f.frag);
163
- this . _updateId3Info ( f . frag ) ;
164
- } ) ;
176
+ instance . on ( HLS . Events . FRAG_CHANGED , ( e , f ) => {
177
+ // this._updateAudioBuffer(f.frag);
178
+ this . _updateId3Info ( f . frag ) ;
165
179
} ) ;
166
180
}
167
181
@@ -267,7 +281,7 @@ export default class HLSSound extends BaseSound {
267
281
268
282
_onHLSError ( error , data , HLS ) {
269
283
if ( data . fatal ) {
270
- this . debug ( data ) ;
284
+ this . debug ( 'HLS fatal error' , data ) ;
271
285
switch ( data . type ) {
272
286
case HLS . ErrorTypes . NETWORK_ERROR :
273
287
this . _giveUpAndDie ( `${ data . details } ` ) ;
0 commit comments