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

WebOS feature: Video Player logic rewrite #79

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
53 changes: 42 additions & 11 deletions src/WebOsVideo/WebOsVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ function WebOsVideo(options) {
throw new Error('Container element required to be instance of HTMLElement');
}

var isLoaded = null;

var knownMediaId = false;

var subSize = 75;
Expand Down Expand Up @@ -212,6 +214,7 @@ function WebOsVideo(options) {
if (info.numAudioTracks) {
for (var i = 0; i < info.audioTrackInfo.length; i++) {
var audioTrack = info.audioTrackInfo[i];
console.log('audioTrack', audioTrack, i); // eslint-disable-line no-console
audioTrack.index = i;
var audioTrackId = 'EMBEDDED_' + audioTrack.index;
if (!currentAudioTrack && !audioTracks.length) {
Expand Down Expand Up @@ -244,15 +247,19 @@ function WebOsVideo(options) {
'subscribe': true
}
}, function (result) {
console.log('luna playback result before result.source', result); // eslint-disable-line no-console
if (result.sourceInfo && !answered) {
answered = true;
var info = result.sourceInfo.programInfo[0];
console.log('sourceInfofrom subscribe function ', info); // eslint-disable-line no-console

setSubs(info);

setTracks(info);

unsubscribe(cb);
} else if (result.sourceInfo) {
console.log('luna playback result', result); // eslint-disable-line no-console
}

if ((result.error || {}).errorCode) {
Expand All @@ -267,20 +274,21 @@ function WebOsVideo(options) {
if ((result.unloadCompleted || {}).mediaId === knownMediaId && (result.unloadCompleted || {}).state) {
// strange case where it just.. ends? without ever getting result.sourceInfo
// onEnded();
// console.log('strange case of end');
console.log('strange case of end', knownMediaId); // eslint-disable-line no-console
// unsubscribe(cb);
return;
}

count_message++;
if(result.bufferRange) {
count_message++;

if (count_message === 30 && !answered) {
// cb();
unsubscribe(cb);
if (count_message === 30 && !answered) {
unsubscribe(cb);
}
}
}, function() { // function(err)
// console.log('luna error log 2');
// console.error(err);
}, function(err) { // function(err)
console.log('luna error log 2'); // eslint-disable-line no-console
console.error(err); // eslint-disable-line no-console
});
};

Expand Down Expand Up @@ -419,6 +427,7 @@ function WebOsVideo(options) {
var subtitlesOpacity = 100;
var observedProps = {
stream: false,
loaded: false,
paused: false,
time: false,
duration: false,
Expand All @@ -443,6 +452,9 @@ function WebOsVideo(options) {
case 'stream': {
return stream;
}
case 'loaded': {
return isLoaded;
}
case 'paused': {
if (stream === null) {
return null;
Expand Down Expand Up @@ -951,6 +963,7 @@ function WebOsVideo(options) {
onPropChanged('stream');
videoElement.autoplay = typeof commandArgs.autoplay === 'boolean' ? commandArgs.autoplay : true;

onPropChanged('loaded');
onPropChanged('paused');
onPropChanged('time');
onPropChanged('duration');
Expand All @@ -965,15 +978,17 @@ function WebOsVideo(options) {

var initMediaId = function (cb) {
function retrieveMediaId() {
console.log('retrieveMediaId run'); // eslint-disable-line no-console
if (videoElement.mediaId) {
knownMediaId = videoElement.mediaId;
console.log('knownMediaId retrievemediaid', knownMediaId); // eslint-disable-line no-console
clearInterval(timer);
subscribe(cb);
return;
}
count++;
if (count > 4) {
// console.log('failed to get media id');
console.log('failed to get media id count > 4'); // eslint-disable-line no-console
clearInterval(timer);
cb();
}
Expand All @@ -982,20 +997,34 @@ function WebOsVideo(options) {
};

var startVideo = function () {
// console.log('startVideo');
console.log('startVideo run'); // eslint-disable-line no-console
console.log(videoElement.mediaId, 'on startvideo func'); // eslint-disable-line no-console
console.log(knownMediaId, 'knownMediaId plaon start func'); // eslint-disable-line no-console
// not needed?
// videoElement.src = stream.url;

try {
isLoaded = true;
onPropChanged('loaded');
console.log(isLoaded, 'video element load'); // eslint-disable-line no-console
videoElement.load();
console.log('videoElement.load() run'); // eslint-disable-line no-console
console.log(knownMediaId, 'knownMediaId after load'); // eslint-disable-line no-console
console.log(videoElement.mediaId, 'after load'); // eslint-disable-line no-console
} catch(e) {
// console.log('can\'t load video');
// console.error(e);
}

try {
// console.log('try play');
isLoaded = true;
onPropChanged('loaded');
console.log(isLoaded, 'video element play'); // eslint-disable-line no-console
videoElement.play();
console.log('videoElement.play() run'); // eslint-disable-line no-console
console.log(knownMediaId, 'knownMediaId after play'); // eslint-disable-line no-console
console.log(videoElement.mediaId), 'after play'; // eslint-disable-line no-console
} catch(e) {
// console.log('can\'t start video');
// console.error(e);
Expand Down Expand Up @@ -1028,7 +1057,9 @@ function WebOsVideo(options) {
// console.log('webos video unload error');
// console.error(e);
// }
isLoaded = false;
onPropChanged('stream');
onPropChanged('loaded');
onPropChanged('paused');
onPropChanged('time');
onPropChanged('duration');
Expand Down Expand Up @@ -1120,7 +1151,7 @@ WebOsVideo.canPlayStream = function() { // function(stream)
WebOsVideo.manifest = {
name: 'WebOsVideo',
external: false,
props: ['stream', 'paused', 'time', 'duration', 'buffering', 'buffered', 'audioTracks', 'selectedAudioTrackId', 'subtitlesTracks', 'selectedSubtitlesTrackId', 'subtitlesOffset', 'subtitlesSize', 'subtitlesTextColor', 'subtitlesBackgroundColor', 'subtitlesOpacity', 'volume', 'muted', 'playbackSpeed'],
props: ['stream', 'loaded', 'paused', 'time', 'duration', 'buffering', 'buffered', 'audioTracks', 'selectedAudioTrackId', 'subtitlesTracks', 'selectedSubtitlesTrackId', 'subtitlesOffset', 'subtitlesSize', 'subtitlesTextColor', 'subtitlesBackgroundColor', 'subtitlesOpacity', 'volume', 'muted', 'playbackSpeed'],
commands: ['load', 'unload', 'destroy'],
events: ['propValue', 'propChanged', 'ended', 'error', 'subtitlesTrackLoaded', 'audioTrackLoaded']
};
Expand Down
Loading