This commit is contained in:
Manav Rathi 2024-11-09 17:45:06 +05:30
parent 5dfd3f3540
commit fab7ecb980
No known key found for this signature in database
2 changed files with 30 additions and 29 deletions

View File

@ -14,7 +14,6 @@ import * as ffmpeg from "@/new/photos/services/ffmpeg";
import { renderableImageBlob } from "@/new/photos/utils/file";
import { ensure } from "@/utils/ensure";
import { CustomError } from "@ente/shared/error";
import { isPlaybackPossible } from "@ente/shared/media/video-playback";
import HTTPService from "@ente/shared/network/HTTPService";
import { retryAsyncFunction } from "@ente/shared/utils";
@ -595,6 +594,36 @@ async function getPlayableVideo(
}
}
const WAIT_FOR_VIDEO_PLAYBACK = 1 * 1000;
async function isPlaybackPossible(url: string): Promise<boolean> {
return await new Promise((resolve) => {
const t = setTimeout(() => {
resolve(false);
}, WAIT_FOR_VIDEO_PLAYBACK);
const video = document.createElement("video");
video.addEventListener("canplay", function () {
clearTimeout(t);
video.remove(); // Clean up the video element
// also check for duration > 0 to make sure it is not a broken video
if (video.duration > 0) {
resolve(true);
} else {
resolve(false);
}
});
video.addEventListener("error", function () {
clearTimeout(t);
video.remove();
resolve(false);
});
video.src = url;
});
}
class PhotosDownloadClient implements DownloadClient {
constructor(
private token: string,

View File

@ -1,28 +0,0 @@
const WAIT_FOR_VIDEO_PLAYBACK = 1 * 1000;
export async function isPlaybackPossible(url: string): Promise<boolean> {
return await new Promise((resolve) => {
const t = setTimeout(() => {
resolve(false);
}, WAIT_FOR_VIDEO_PLAYBACK);
const video = document.createElement("video");
video.addEventListener("canplay", function () {
clearTimeout(t);
video.remove(); // Clean up the video element
// also check for duration > 0 to make sure it is not a broken video
if (video.duration > 0) {
resolve(true);
} else {
resolve(false);
}
});
video.addEventListener("error", function () {
clearTimeout(t);
video.remove();
resolve(false);
});
video.src = url;
});
}