Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard async callbacks in TizenVideo #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions src/TizenVideo/TizenVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function TizenVideo(options) {

var events = new EventEmitter();
var destroyed = false;
var stream = null;
var loadArgs = null;
var retries = 0;
var maxRetries = 5;
var isLoaded = null;
Expand All @@ -151,13 +151,13 @@ function TizenVideo(options) {
function getProp(propName) {
switch (propName) {
case 'stream': {
return stream;
return loadArgs !== null ? loadArgs.stream : null;
}
case 'loaded': {
return isLoaded;
}
case 'paused': {
if (stream === null) {
if (loadArgs === null) {
return null;
}

Expand All @@ -172,29 +172,29 @@ function TizenVideo(options) {
}
case 'time': {
var currentTime = window.webapis.avplay.getCurrentTime();
if (stream === null || currentTime === null || !isFinite(currentTime)) {
if (loadArgs === null || currentTime === null || !isFinite(currentTime)) {
return null;
}

return Math.floor(currentTime);
}
case 'duration': {
var duration = window.webapis.avplay.getDuration();
if (stream === null || duration === null || !isFinite(duration)) {
if (loadArgs === null || duration === null || !isFinite(duration)) {
return null;
}

return Math.floor(duration);
}
case 'buffering': {
if (stream === null) {
if (loadArgs === null) {
return null;
}

return isBuffering;
}
case 'subtitlesTracks': {
if (stream === null) {
if (loadArgs === null) {
return [];
}

Expand Down Expand Up @@ -227,7 +227,7 @@ function TizenVideo(options) {
return textTracks;
}
case 'selectedSubtitlesTrackId': {
if (stream === null || disabledSubs) {
if (loadArgs === null || disabledSubs) {
return null;
}

Expand Down Expand Up @@ -288,7 +288,7 @@ function TizenVideo(options) {
return subtitlesOpacity;
}
case 'audioTracks': {
if (stream === null) {
if (loadArgs === null) {
return [];
}

Expand Down Expand Up @@ -321,7 +321,7 @@ function TizenVideo(options) {
return audioTracks;
}
case 'selectedAudioTrackId': {
if (stream === null) {
if (loadArgs === null) {
return null;
}

Expand Down Expand Up @@ -377,7 +377,7 @@ function TizenVideo(options) {
function setProp(propName, propValue) {
switch (propName) {
case 'paused': {
if (stream !== null) {
if (loadArgs !== null) {
var willPause = !!propValue;
willPause ? window.webapis.avplay.pause() : window.webapis.avplay.play();
if (willPause) {
Expand All @@ -404,7 +404,7 @@ function TizenVideo(options) {
break;
}
case 'time': {
if (stream !== null && propValue !== null && isFinite(propValue)) {
if (loadArgs !== null && propValue !== null && isFinite(propValue)) {
window.webapis.avplay.seekTo(parseInt(propValue, 10));
renderSubtitle(1, '');
onPropChanged('time');
Expand All @@ -413,7 +413,7 @@ function TizenVideo(options) {
break;
}
case 'selectedSubtitlesTrackId': {
if (stream !== null) {
if (loadArgs !== null) {
if ((currentSubTrack || '').indexOf('EMBEDDED_') === 0) {
if ((propValue || '').indexOf('EMBEDDED_') === -1) {
renderSubtitle(1, '');
Expand Down Expand Up @@ -527,7 +527,7 @@ function TizenVideo(options) {
break;
}
case 'selectedAudioTrackId': {
if (stream !== null) {
if (loadArgs !== null) {

currentAudioTrack = propValue;

Expand Down Expand Up @@ -574,18 +574,17 @@ function TizenVideo(options) {
switch (commandName) {
case 'load': {
if (commandArgs && commandArgs.stream && typeof commandArgs.stream.url === 'string') {
stream = commandArgs.stream;

if (stream !== commandArgs.stream) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only thing thats missing in this PR is this check over here which allways resolve to false in the current master branch since the check is made after the update of the local stream var.
Do we need this check?
All other video implementations do command("unload") from within the body of the load action handler but maybe there is something Tizen specific here?

return;
}
loadArgs = commandArgs;
onPropChanged('buffering');

window.webapis.avplay.open(stream.url);
window.webapis.avplay.open(commandArgs.stream.url);
window.webapis.avplay.setDisplayRect(0, 0, window.innerWidth, window.innerHeight);
window.webapis.avplay.setDisplayMethod('PLAYER_DISPLAY_MODE_LETTER_BOX');
window.webapis.avplay.seekTo(commandArgs.time !== null && isFinite(commandArgs.time) ? parseInt(commandArgs.time, 10) : 0);
window.webapis.avplay.prepareAsync(function() {
if (commandArgs !== loadArgs) {
return;
}

onPropChanged('duration');
window.webapis.avplay.play();

Expand All @@ -600,6 +599,10 @@ function TizenVideo(options) {
onPropChanged('audioTracks');
onPropChanged('selectedAudioTrackId');
}, function(error) {
if (commandArgs !== loadArgs) {
return;
}

if (retries < maxRetries) {
retries++;
try {
Expand All @@ -623,7 +626,7 @@ function TizenVideo(options) {
break;
}
case 'unload': {
stream = null;
loadArgs = null;
window.webapis.avplay.stop();
isLoaded = false;
onPropChanged('loaded');
Expand Down
Loading