Skip to content

Commit

Permalink
Youtube Video Fix (#2234)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisrijsdijk committed Sep 17, 2023
1 parent e5340de commit 683ae70
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
31 changes: 10 additions & 21 deletions src/backend/effects/builtin/play-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,17 +443,23 @@ const playVideo = {

let resourceToken;
let duration;
if (effect.videoType === "YouTube Video") {
if (effect.videoType === "YouTube Video" && !effect.wait) {
logger.debug("Play Video Effect: Proceeding without Youtube Video Duration because wait is false");
} else if (effect.videoType === "YouTube Video" && effect.wait) {
const youtubeData = parseYoutubeId(data.youtubeId);
data.youtubeId = youtubeData.id;
const result = await frontendCommunicator.fireEventAsync("getYoutubeVideoDuration", data.youtubeId);
if (!isNaN(result)) {
duration = result;
} else {
// Error
logger.error("Play Video Effect: Unable to retrieve Youtube Video Duration", result);
return;
}
if (data.videoStarttime == null || data.videoStarttime == "" || data.videoStarttime == 0) {
data.videoStarttime = youtubeData.startTime;
}
} else {
} else if (effect.videoType === "Local Video") {
const result = await frontendCommunicator.fireEventAsync("getVideoDuration", data.filepath);
if (!isNaN(result)) {
duration = result;
Expand All @@ -464,24 +470,7 @@ const playVideo = {
data.resourceToken = resourceToken;

webServer.sendToOverlay("video", data);
if (effect.wait && effect.videoType === "YouTube Video") {
// Use overlay callback for youtube video, needs local way to get duration for production.
// If effect is ran with "Wait for video to finish" while overlay is not open, it may freeze an effect queue.
await new Promise(async (resolve, reject) => {
const listener = (event) => {
try {
if (event.name === "video-end" && event.data.resourceToken === resourceToken) {
webServer.removeListener("overlay-event", listener);
resolve();
}
} catch (err) {
logger.error("Error while trying to process overlay-event for play-video: ", err);
reject(err);
}
};
webServer.on("overlay-event", listener);
});
} else if (effect.wait && data.videoType === "Local Video") {
if (effect.wait) {
let internalDuration = data.videoDuration;
if (internalDuration == null || internalDuration === 0 || internalDuration === "") {
internalDuration = duration;
Expand Down Expand Up @@ -544,7 +533,7 @@ const playVideo = {
const data = event;

const videoType = data.videoType;
const filepath = data.filepath;
const filepath = data.filepath ?? "";
let fileExt = filepath.split(".").pop();
if (fileExt === "ogv") {
fileExt = "ogg";
Expand Down
15 changes: 9 additions & 6 deletions src/gui/app/services/video.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
onReady: (event) => {
event.target.setVolume(0);
event.target.playVideo();
if (player.getDuration() === 0) {
return;
}
resolve(player.getDuration());
document.getElementById(id).remove();
},
Expand All @@ -54,16 +57,16 @@
code: event.data,
youtubeId: videoId
};
if (event.data === 2) {
if (event.data === "2") {
error.error = "The request contains an invalid parameter value.";
}
if (event.data === 5) {
if (event.data === "5") {
error.error = "The requested content cannot be played in an HTML5 player or another error related to the HTML5 player has occurred.";
}
if (event.data === 100) {
if (event.data === "100") {
error.error = "The video requested was not found. This error occurs when a video has been removed (for any reason) or has been marked as private.";
}
if (event.data === 101 || event.data === 150) {
if (event.data === "101" || event.data === "150") {
error.error = "The owner of the requested video does not allow it to be played in embedded players.";
}
resolve(error);
Expand All @@ -75,11 +78,11 @@
};

backendCommunicator.onAsync("getVideoDuration", async (path) => {
return service.getVideoDuration(path);
return await service.getVideoDuration(path);
});

backendCommunicator.onAsync("getYoutubeVideoDuration", async (youtubeId) => {
return service.getYoutubeVideoDuration(youtubeId);
return await service.getYoutubeVideoDuration(youtubeId);
});

return service;
Expand Down

0 comments on commit 683ae70

Please sign in to comment.