File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,11 @@ MediaElementPlayer.prototype.init = function(eventEmitter) {
9191 if ( ! mediaElementHasSource ( self . _mediaElement ) ) {
9292 return Promise . resolve ( ) ;
9393 }
94+ else if ( self . _mediaElement . error &&
95+ self . _mediaElement . error . code === MediaError . MEDIA_ERR_SRC_NOT_SUPPORTED ) {
96+ // The media element has a source, but the format is not supported.
97+ return Promise . reject ( self . _mediaElement . error ) ;
98+ }
9499
95100 return new Promise ( function ( resolve , reject ) {
96101 function eventHandler ( event ) {
Original file line number Diff line number Diff line change @@ -483,6 +483,40 @@ describe('Peaks', function() {
483483 } ) ;
484484 } ) ;
485485 } ) ;
486+
487+ context ( 'with audio element in error state' , function ( ) {
488+ let mediaElement ;
489+
490+ beforeEach ( function ( ) {
491+ mediaElement = document . createElement ( 'audio' ) ;
492+ mediaElement . id = 'adpcm' ;
493+ mediaElement . src = '/base/test_data/adpcm.wav' ;
494+ mediaElement . muted = true ;
495+ document . body . appendChild ( mediaElement ) ;
496+ } ) ;
497+
498+ afterEach ( function ( ) {
499+ document . body . removeChild ( mediaElement ) ;
500+ } ) ;
501+
502+ it ( 'should invoke callback with an error' , function ( done ) {
503+ Peaks . init ( {
504+ overview : {
505+ container : document . getElementById ( 'overview-container' )
506+ } ,
507+ zoomview : {
508+ container : document . getElementById ( 'zoomview-container' )
509+ } ,
510+ mediaElement : document . getElementById ( 'adpcm' ) ,
511+ dataUri : { arraybuffer : '/base/test_data/sample.dat' }
512+ } , function ( err , instance ) {
513+ expect ( err ) . to . be . an . instanceOf ( MediaError ) ;
514+ expect ( err . code ) . to . equal ( MediaError . MEDIA_ERR_SRC_NOT_SUPPORTED ) ;
515+ expect ( instance ) . to . equal ( undefined ) ;
516+ done ( ) ;
517+ } ) ;
518+ } ) ;
519+ } ) ;
486520 } ) ;
487521
488522 context ( 'with invalid options' , function ( ) {
You can’t perform that action at this time.
0 commit comments