setting aspect ratio only to videos that are playing works

This commit is contained in:
Tamius Han 2018-11-21 21:58:13 +01:00
parent c6ad32f712
commit 4d21187596
3 changed files with 153 additions and 53 deletions

View File

@ -66,26 +66,26 @@ class CommsClient {
} }
if (message.cmd === "set-ar") { if (message.cmd === "set-ar") {
this.pageInfo.setAr(message.arg); this.pageInfo.setAr(message.arg, message.playing);
} else if (message.cmd === 'set-alignment') { } else if (message.cmd === 'set-alignment') {
this.pageInfo.setVideoFloat(message.arg); this.pageInfo.setVideoFloat(message.arg, message.playing);
this.pageInfo.restoreAr(); this.pageInfo.restoreAr();
} else if (message.cmd === "set-stretch") { } else if (message.cmd === "set-stretch") {
this.pageInfo.setStretchMode(StretchMode[message.arg]); this.pageInfo.setStretchMode(StretchMode[message.arg], message.playing);
} else if (message.cmd === "autoar-start") { } else if (message.cmd === "autoar-start") {
if (message.enabled !== false) { if (message.enabled !== false) {
this.pageInfo.initArDetection(); this.pageInfo.initArDetection(message.playing);
this.pageInfo.startArDetection(); this.pageInfo.startArDetection(message.playing);
} else { } else {
this.pageInfo.stopArDetection(); this.pageInfo.stopArDetection(message.playing);
} }
} else if (message.cmd === "pause-processing") { } else if (message.cmd === "pause-processing") {
this.pageInfo.pauseProcessing(); this.pageInfo.pauseProcessing(message.playing);
} else if (message.cmd === "resume-processing") { } else if (message.cmd === "resume-processing") {
// todo: autoArStatus // todo: autoArStatus
this.pageInfo.resumeProcessing(message.autoArStatus); this.pageInfo.resumeProcessing(message.autoArStatus, message.playing);
} else if (message.cmd === 'set-zoom') { } else if (message.cmd === 'set-zoom') {
this.pageInfo.setZoom(message.zoom, true); this.pageInfo.setZoom(message.zoom, true, message.playing);
} }
} }

View File

@ -186,4 +186,13 @@ class VideoData {
announceZoom(scale){ announceZoom(scale){
this.pageInfo.announceZoom(scale); this.pageInfo.announceZoom(scale);
} }
isPlaying() {
console.log("is playing? video:", this.video, "ctime:", this.video.currentTime,
"paused/ended:", this.video.paused, this.video.ended,
"is playing?", this.video && this.video.currentTime > 0 && !this.video.paused && !this.video.ended);
return this.video && this.video.currentTime > 0 && !this.video.paused && !this.video.ended;
}
} }

View File

@ -196,55 +196,98 @@ class PageInfo {
this.scheduleUrlCheck(); this.scheduleUrlCheck();
} }
initArDetection(){ initArDetection(playingOnly){
for(var vd of this.videos){ if (playingOnly) {
vd.initArDetection(); for(var vd of this.videos){
if(vd.isPlaying()) {
vd.initArDetection();
}
}
return;
} else {
for(var vd of this.videos){
vd.initArDetection();
}
} }
} }
// to je treba klicat ob menjavi zavihkov // to je treba klicat ob menjavi zavihkov
// these need to be called on tab switch // these need to be called on tab switch
pauseProcessing(){ pauseProcessing(playingOnly){
for(var vd of this.videos){ if (playingOnly) {
vd.pause(); for(var vd of this.videos){
if (vd.isPlaying()) {
vd.pause();
}
}
} else {
for(var vd of this.videos){
vd.pause();
}
} }
} }
resumeProcessing(resumeAutoar = false){ resumeProcessing(resumeAutoar = false, playingOnly = false){
for(var vd of this.videos){ if (playingOnly) {
vd.resume(); for(var vd of this.videos){
if(resumeAutoar){ if (vd.isPlaying()) {
vd.resumeAutoAr(); vd.resume();
if(resumeAutoar){
vd.resumeAutoAr();
}
}
}
} else {
for(var vd of this.videos){
vd.resume();
if(resumeAutoar){
vd.resumeAutoAr();
}
} }
} }
} }
startArDetection(){ startArDetection(playingOnly){
if (Debug.debug) { if (Debug.debug) {
console.log('[PageInfo::startArDetection()] starting automatic ar detection!') console.log('[PageInfo::startArDetection()] starting automatic ar detection!')
} }
for(var vd of this.videos){ if (playingOnly) {
vd.startArDetection(); for(var vd of this.videos){
if (video.isPlaying()) {
vd.startArDetection();
}
}
} else {
for(var vd of this.videos){
vd.startArDetection();
}
} }
} }
stopArDetection(){ stopArDetection(playingOnly){
for(var vd of this.videos){ if (playingOnly) {
vd.stopArDetection(); for(var vd of this.videos){
if (vd.isPlaying()) {
vd.stopArDetection();
}
}
} else {
for(var vd of this.videos){
vd.stopArDetection();
}
} }
} }
setAr(ar){ setAr(ar, playingOnly){
if (Debug.debug) { if (Debug.debug) {
console.log('[PageInfo::setAr] aspect ratio:', ar) console.log('[PageInfo::setAr] aspect ratio:', ar, "playing only?", playingOnly)
} }
if (ar !== 'auto') { if (ar !== 'auto') {
this.stopArDetection(); this.stopArDetection(playingOnly);
} else { } else {
if (Debug.debug) { if (Debug.debug) {
console.log('[PageInfo::setAr] aspect ratio is auto'); console.log('[PageInfo::setAr] aspect ratio is auto');
@ -252,63 +295,111 @@ class PageInfo {
try { try {
for (var vd of this.videos) { for (var vd of this.videos) {
vd.resetLastAr(); if (!playingOnly || vd.isPlaying()) {
vd.resetLastAr();
}
} }
} catch (e) { } catch (e) {
console.log("???", e); console.log("???", e);
} }
this.initArDetection(); this.initArDetection(playingOnly);
this.startArDetection(); this.startArDetection(playingOnly);
return; return;
} }
// TODO: find a way to only change aspect ratio for one video // TODO: find a way to only change aspect ratio for one video
if (ar === 'reset') { if (ar === 'reset') {
for (var vd of this.videos) { for (var vd of this.videos) {
vd.resetAr(); if (!playingOnly || vd.isPlaying()) {
vd.resetAr();
}
} }
} else { } else {
for (var vd of this.videos) { for (var vd of this.videos) {
vd.setAr(ar) if (!playingOnly || vd.isPlaying()) {
vd.setAr(ar)
}
} }
} }
} }
setVideoFloat(videoFloat) { setVideoFloat(videoFloat, playingOnly) {
for(var vd of this.videos) { if (playingOnly) {
vd.setVideoFloat(videoFloat) for(var vd of this.videos) {
if (vd.isPlaying()) {
vd.setVideoFloat(videoFloat)
}
}
} else {
for(var vd of this.videos) {
vd.setVideoFloat(videoFloat)
}
} }
} }
setPanMode(mode) { setPanMode(mode, playingOnly) {
for(var vd of this.videos) { if (playingOnly) {
vd.setPanMode(mode); for(var vd of this.videos) {
if (vd.isPlaying()) {
vd.setPanMode(mode);
}
}
} else {
for(var vd of this.videos) {
vd.setPanMode(mode);
}
} }
} }
restoreAr() { restoreAr(playingOnly) {
for(var vd of this.videos){ if (playingOnly) {
vd.restoreAr() for(var vd of this.videos){
if (vd.isPlaying()) {
vd.restoreAr();
}
}
} else {
for(var vd of this.videos){
vd.restoreAr();
}
} }
} }
setStretchMode(sm){ setStretchMode(sm, playingOnly){
// TODO: find a way to only change aspect ratio for one video // TODO: find a way to only change aspect ratio for one video
for(var vd of this.videos){ if (playingOnly) {
vd.setStretchMode(sm) for(var vd of this.videos){
if (vd.isPlaying()) {
vd.setStretchMode(sm)
}
}
} else {
for(var vd of this.videos){
vd.setStretchMode(sm)
}
} }
} }
setZoom(zoomLevel, no_announce) { setZoom(zoomLevel, no_announce, playingOnly) {
for(var vd of this.videos) { if (playingOnly) {
vd.setZoom(zoomLevel, no_announce); for(var vd of this.videos) {
if (vd.isPlaying()) {
vd.setZoom(zoomLevel, no_announce);
}
}
} else {
for(var vd of this.videos) {
vd.setZoom(zoomLevel, no_announce);
}
} }
} }
zoomStep(step){ zoomStep(step, playingOnly) {
for(var vd of this.videos){ for(var vd of this.videos){
vd.zoomStep(step); if (!playingOnly || vd.isPlaying()) {
vd.zoomStep(step);
}
} }
} }