Skip to content

Commit

Permalink
Use loaded Prop
Browse files Browse the repository at this point in the history
  • Loading branch information
jaruba committed Mar 1, 2024
1 parent 7dc567d commit 1c25633
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 19 deletions.
11 changes: 10 additions & 1 deletion src/TizenVideo/TizenVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ function TizenVideo(options) {
var stream = null;
var retries = 0;
var maxRetries = 5;
var isLoaded = null;
var observedProps = {
stream: false,
loaded: false,
paused: false,
time: false,
duration: false,
Expand All @@ -154,6 +156,9 @@ function TizenVideo(options) {
case 'stream': {
return stream;
}
case 'loaded': {
return isLoaded;
}
case 'paused': {
if (stream === null) {
return null;
Expand Down Expand Up @@ -600,6 +605,8 @@ function TizenVideo(options) {
onPropChanged('duration');
window.webapis.avplay.play();

isLoaded = true;
onPropChanged('loaded');
onPropChanged('stream');
onPropChanged('paused');
onPropChanged('time');
Expand Down Expand Up @@ -638,6 +645,8 @@ function TizenVideo(options) {
case 'unload': {
stream = null;
window.webapis.avplay.stop();
isLoaded = false;
onPropChanged('loaded');
onPropChanged('stream');
onPropChanged('paused');
onPropChanged('time');
Expand Down Expand Up @@ -707,7 +716,7 @@ TizenVideo.canPlayStream = function() {
TizenVideo.manifest = {
name: 'TizenVideo',
external: false,
props: ['stream', 'paused', 'time', 'duration', 'buffering', 'audioTracks', 'selectedAudioTrackId', 'subtitlesTracks', 'selectedSubtitlesTrackId', 'subtitlesOffset', 'subtitlesSize', 'subtitlesTextColor', 'subtitlesBackgroundColor', 'subtitlesOutlineColor', 'subtitlesOpacity', 'playbackSpeed'],
props: ['stream', 'loaded', 'paused', 'time', 'duration', 'buffering', 'audioTracks', 'selectedAudioTrackId', 'subtitlesTracks', 'selectedSubtitlesTrackId', 'subtitlesOffset', 'subtitlesSize', 'subtitlesTextColor', 'subtitlesBackgroundColor', 'subtitlesOutlineColor', 'subtitlesOpacity', 'playbackSpeed'],
commands: ['load', 'unload', 'destroy'],
events: ['propValue', 'propChanged', 'ended', 'error', 'subtitlesTrackLoaded', 'audioTrackLoaded']
};
Expand Down
37 changes: 20 additions & 17 deletions src/withStreamingServer/fetchVideoParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,29 @@ function fetchFilename(streamingServerURL, mediaURL, infoHash, fileIdx, behavior
}

function fetchVideoParams(streamingServerURL, mediaURL, infoHash, fileIdx, behaviorHints) {
var result = { hash: null, size: null, filename: null };
// these need to be sequential as fetchOpensubtitlesParams
// ensures engine /stats.json availability
return fetchOpensubtitlesParams(streamingServerURL, mediaURL, behaviorHints)
.then(function(res) {
result.hash = res.hash;
result.size = res.size;
return fetchFilename(streamingServerURL, mediaURL, infoHash, fileIdx, behaviorHints);
})
.then(function(res) {
return Promise.allSettled([
fetchOpensubtitlesParams(streamingServerURL, mediaURL, behaviorHints),
fetchFilename(streamingServerURL, mediaURL, infoHash, fileIdx, behaviorHints)
]).then(function(results) {
var result = { hash: null, size: null, filename: null };

if (res) {
result.filename = res;
}
if (results[0].status === 'fulfilled') {
result.hash = results[0].value.hash;
result.size = results[0].value.size;
} else if (results[0].reason) {
// eslint-disable-next-line no-console
console.error(results[0].reason);
}

return result;
}).catch(function(e) {
if (results[1].status === 'fulfilled') {
result.filename = results[1].value;
} else if (results[1].reason) {
// eslint-disable-next-line no-console
console.error(e);
});
console.error(results[1].reason);
}

return result;
});
}

module.exports = fetchVideoParams;
24 changes: 24 additions & 0 deletions src/withStreamingServer/isPlayerLoaded.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function isPlayerLoaded(video, props) {
if (!props.includes('loaded')) {
return Promise.resolve(true);
}
return new Promise(function(resolve, reject) {
var isLoaded = null;
video.on('propChanged', function(propName, propValue) {
if (propName === 'loaded' && propValue !== null && isLoaded === null) {
isLoaded = propValue;
if (propValue === true) {
resolve(true);
} else if (propValue === false) {
reject(Error('Player failed to load, will not retrieve video params'));
}
}
});
video.dispatch({
type: 'observeProp',
propName: 'loaded'
});
});
}

module.exports = isPlayerLoaded;
7 changes: 6 additions & 1 deletion src/withStreamingServer/withStreamingServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var deepFreeze = require('deep-freeze');
var mediaCapabilities = require('../mediaCapabilities');
var convertStream = require('./convertStream');
var fetchVideoParams = require('./fetchVideoParams');
var isPlayerLoaded = require('./isPlayerLoaded');
var supportsTranscoding = require('../supportsTranscoding');
var ERROR = require('../error');

Expand Down Expand Up @@ -203,7 +204,11 @@ function withStreamingServer(Video) {
});
loaded = true;
flushActionsQueue();
fetchVideoParams(commandArgs.streamingServerURL, result.mediaURL, result.infoHash, result.fileIdx, commandArgs.stream.behaviorHints)

isPlayerLoaded(video, Video.manifest.props)
.then(function() {
return fetchVideoParams(commandArgs.streamingServerURL, result.mediaURL, result.infoHash, result.fileIdx, commandArgs.stream.behaviorHints);
})
.then(function(result) {
if (commandArgs !== loadArgs) {
return;
Expand Down

0 comments on commit 1c25633

Please sign in to comment.