Skip to content

Commit 08bf2da

Browse files
committed
Added check for media element error state on initialisation
See #523
1 parent 5d006c1 commit 08bf2da

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/mediaelement-player.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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) {

test/api-spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff 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() {

test_data/adpcm.wav

60.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)