@@ -76,7 +76,7 @@ interface PlayerProps {
76
76
onClickPrevious ?: ( e : React . SyntheticEvent ) => void
77
77
onClickNext ?: ( e : React . SyntheticEvent ) => void
78
78
onPlayError ?: ( err : Error ) => void
79
- onChangeCurrentTimeError ?: ( ) => void
79
+ onChangeCurrentTimeError ?: ( err : Error ) => void
80
80
mse ?: MSEPropsObject
81
81
/**
82
82
* HTML5 Audio tag preload property
@@ -217,6 +217,9 @@ class H5AudioPlayer extends Component<PlayerProps> {
217
217
* Reference: https://developers.google.com/web/updates/2017/06/play-request-was-interrupted
218
218
*/
219
219
playAudioPromise = ( ) : void => {
220
+ if ( this . audio . current . error ) {
221
+ this . audio . current . load ( )
222
+ }
220
223
const playPromise = this . audio . current . play ( )
221
224
// playPromise is null in IE 11
222
225
if ( playPromise ) {
@@ -299,7 +302,11 @@ class H5AudioPlayer extends Component<PlayerProps> {
299
302
! isFinite ( duration ) ||
300
303
! isFinite ( prevTime )
301
304
) {
302
- return this . props . onChangeCurrentTimeError && this . props . onChangeCurrentTimeError ( )
305
+ try {
306
+ audio . load ( )
307
+ } catch ( err ) {
308
+ return this . props . onChangeCurrentTimeError && this . props . onChangeCurrentTimeError ( err as Error )
309
+ }
303
310
}
304
311
let currentTime = prevTime + time / 1000
305
312
if ( currentTime < 0 ) {
@@ -573,6 +580,11 @@ class H5AudioPlayer extends Component<PlayerProps> {
573
580
}
574
581
575
582
audio . addEventListener ( 'error' , ( e ) => {
583
+ const target = e . target as HTMLAudioElement
584
+ // Calls onEnded when currentTime is the same as duration even if there is an error
585
+ if ( target . error && target . currentTime === target . duration ) {
586
+ return this . props . onEnded && this . props . onEnded ( e )
587
+ }
576
588
this . props . onError && this . props . onError ( e )
577
589
} )
578
590
0 commit comments