Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var thisM = Media.get(id);
// if Media was released, then node will be null and we need to create it again
if (!thisM.node) {
args[2] = true; // Setting createAudioNode to true
if (!module.exports.create(win, lose, args)) {
// there is no reason to continue if we can't create media
// corresponding callback has been invoked in create so we don't need to call it here
return;
}
}
try {
thisM.node.play();
} catch (err) {
if (lose) {
lose({code:MediaError.MEDIA_ERR_ABORTED});
}
}
},
thisM.node.onerror = function (e) {
// Due to media.spec.15 It should return MediaError for bad filename
var err = e.target.error.code === MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED ?
{ code: MediaError.MEDIA_ERR_ABORTED } :
e.target.error;
Media.onStatus(id, Media.MEDIA_ERROR, err);
};
stopPlayingAudio:function(successCallback, errorCallback, args) {
var id = args[0];
window.clearTimeout(audioObjects[id].timer);
audioObjects[id].pause();
if (audioObjects[id].currentTime !== 0)
audioObjects[id].currentTime = 0;
console.log("media::stopPlayingAudio() - MEDIA_STATE -> MEDIA_STOPPED");
Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STOPPED);
audioObjects[id].removeEventListener('canplay', audioObjects[id].onCanPlayCB);
audioObjects[id].removeEventListener('ended', audioObjects[id].onEndedCB);
audioObjects[id].removeEventListener('timeupdate', audioObjects[id].onTimeUpdateCB);
audioObjects[id].removeEventListener('durationchange', audioObjects[id].onDurationChangeCB);
audioObjects[id].removeEventListener('playing', audioObjects[id].onPlayingCB);
audioObjects[id].removeEventListener('play', audioObjects[id].onPlayCB);
audioObjects[id].removeEventListener('error', audioObjects[id].onErrorCB);
audioObjects[id].removeEventListener('error', audioObjects[id].onStalledCB);
},
audioObjects[id].onDurationChangeCB = function () {
console.log("media::onDurationChangeCB() - MEDIA_DURATION -> " + audioObjects[id].duration);
Media.onStatus(id, Media.MEDIA_DURATION, audioObjects[id].duration);
};
audioObjects[id].onEndedCB = function () {
console.log("media::onEndedCB() - MEDIA_STATE -> MEDIA_STOPPED");
Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_STOPPED);
};
pausePlayingAudio:function(successCallback, errorCallback, args) {
var id = args[0];
console.log("media::pausePlayingAudio() - MEDIA_STATE -> MEDIA_PAUSED");
audioObjects[id].pause();
Media.onStatus(id, Media.MEDIA_STATE, Media.MEDIA_PAUSED);
},
function () {
audioObjects[id].pause();
if (audioObjects[id].currentTime !== 0)
audioObjects[id].currentTime = 0;
console.log("media::onStalled() - MEDIA_ERROR -> " + MediaError.MEDIA_ERR_ABORTED);
var err = new MediaError(MediaError.MEDIA_ERR_ABORTED, "Stalled");
Media.onStatus(id, Media.MEDIA_ERROR, err);
},
2000);
function () {
audioObjects[id].pause();
if (audioObjects[id].currentTime !== 0)
audioObjects[id].currentTime = 0;
console.log("media::onStalled() - MEDIA_ERROR -> " + MediaError.MEDIA_ERR_ABORTED);
var err = new MediaError(MediaError.MEDIA_ERR_ABORTED, "Stalled");
Media.onStatus(id, Media.MEDIA_ERROR, err);
},
2000);
function () {
audioObjects[id].pause();
if (audioObjects[id].currentTime !== 0)
audioObjects[id].currentTime = 0;
console.log("media::onStalled() - MEDIA_ERROR -> " + MediaError.MEDIA_ERR_ABORTED);
var err = new MediaError(MediaError.MEDIA_ERR_ABORTED, "Stalled");
Media.onStatus(id, Media.MEDIA_ERROR, err);
},
2000);
audioObjects[id].onTimeUpdateCB = function () {
console.log("media::onTimeUpdateCB() - MEDIA_POSITION -> " + audioObjects[id].currentTime);
Media.onStatus(id, Media.MEDIA_POSITION, audioObjects[id].currentTime);
};