Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #32041 from jimporter/music-check-playability-fix
Browse files Browse the repository at this point in the history
Bug 1208331 - [music] Fix checkPlayability (again)
  • Loading branch information
Jim Porter committed Sep 26, 2015
2 parents 3b42b49 + bebd13d commit 5867322
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 15 additions & 1 deletion apps/music/js/metadata/core.js
Expand Up @@ -137,14 +137,28 @@ var AudioMetadata = (function() {
var url = URL.createObjectURL(blob);
player.src = url;

player.onerror = player.onsuspend = function() {
// XXX: There seems to have been a gecko regression, and error events
// are no longer being fired when we try to play some invalid audio
// files. To work around this, we use a timeout to assume the file is
// unplayable if we nave not gotten any events within a reasonable
// amount of time. See also bugs 1208331 and 1198169.
const CANPLAY_TIMEOUT = 3000;
var timeoutId = setTimeout(() => {
console.error('No oncanplay or error events seen yet.',
'Assuming file is corrupt:', blob.name);
player.onerror();
}, CANPLAY_TIMEOUT);

player.onerror = function() {
clearTimeout(timeoutId);
URL.revokeObjectURL(url);
player.removeAttribute('src');
player.load();
reject('Unplayable music file');
};

player.oncanplay = function() {
clearTimeout(timeoutId);
URL.revokeObjectURL(url);
player.removeAttribute('src');
player.load();
Expand Down
16 changes: 15 additions & 1 deletion dev_apps/music-nga/js/metadata/core.js
Expand Up @@ -137,14 +137,28 @@ var AudioMetadata = (function() {
var url = URL.createObjectURL(blob);
player.src = url;

player.onerror = player.onsuspend = function() {
// XXX: There seems to have been a gecko regression, and error events
// are no longer being fired when we try to play some invalid audio
// files. To work around this, we use a timeout to assume the file is
// unplayable if we nave not gotten any events within a reasonable
// amount of time. See also bugs 1208331 and 1198169.
const CANPLAY_TIMEOUT = 3000;
var timeoutId = setTimeout(() => {
console.error('No oncanplay or error events seen yet.',
'Assuming file is corrupt:', blob.name);
player.onerror();
}, CANPLAY_TIMEOUT);

player.onerror = function() {
clearTimeout(timeoutId);
URL.revokeObjectURL(url);
player.removeAttribute('src');
player.load();
reject('Unplayable music file');
};

player.oncanplay = function() {
clearTimeout(timeoutId);
URL.revokeObjectURL(url);
player.removeAttribute('src');
player.load();
Expand Down

0 comments on commit 5867322

Please sign in to comment.