From 96e033b23d7c68513dc4564085c203e5bd1eae86 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sat, 30 Sep 2023 14:14:36 -0700 Subject: [PATCH] nx: force local video when available Signed-off-by: Varun Patil --- src/components/viewer/PsVideo.ts | 17 ++++++----------- src/native.ts | 30 +++++++++++------------------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/components/viewer/PsVideo.ts b/src/components/viewer/PsVideo.ts index 79e9d7cd..0516aa7a 100644 --- a/src/components/viewer/PsVideo.ts +++ b/src/components/viewer/PsVideo.ts @@ -138,17 +138,12 @@ class VideoContentSetup { // Hand off to native player if available if (nativex.has()) { - const fileid = content.data.photo.fileid; - // Local videos are played back directly - if (utils.isLocalPhoto(content.data.photo)) { - nativex.playVideoLocal(fileid); - return; - } - - // Use both remote sources - const urls = sources.map((s) => s.src); - nativex.playVideoRemote(fileid, urls); + // Remote videos are played back via HLS / Direct + nativex.playVideo( + content.data.photo, + sources.map((s) => s.src) + ); return; } @@ -259,7 +254,7 @@ class VideoContentSetup { // Add a timeout in case another video initializes // immediately after this one is destroyed setTimeout(() => { - nativex.destroyVideo(content.data.photo.fileid); + nativex.destroyVideo(content.data.photo); }, 500); } diff --git a/src/native.ts b/src/native.ts index 8ac13a98..b5b572f6 100644 --- a/src/native.ts +++ b/src/native.ts @@ -126,18 +126,14 @@ export type NativeX = { downloadFromUrl: (url: string, filename: string) => void; /** - * Play a video from the given file ID (local file). - * @param fileid File ID of the video - */ - playVideoLocal: (fileid: string) => void; - /** - * Play a video from the given URL(s). - * @param fileid Remote file ID of the video (used for play tracking) + * Play a video from the given AUID or URL(s). + * @param auid AUID of file (will play local if available) + * @param fileid File ID of the video (only used for file tracking) * @param urlArray JSON-encoded array of URLs to play * @details The URL array may contain multiple URLs, e.g. direct playback * and HLS separately. The native client must try to play the first URL. */ - playVideoRemote: (fileid: string, urlArray: string) => void; + playVideo: (auid: string, fileid: string, urlArray: string) => void; /** * Destroy the video player. * @param fileid File ID of the video @@ -224,25 +220,21 @@ export async function playTouchSound() { nativex?.playTouchSound?.(); } -/** - * Play a video from the given file ID (local file). - */ -export async function playVideoLocal(fileid: number) { - nativex?.playVideoLocal?.(fileid.toString()); -} - /** * Play a video from the given URL. + * @param photo Photo to play + * @param urls URLs to play (remote) */ -export async function playVideoRemote(fileid: number, urls: string[]) { - nativex?.playVideoRemote?.(fileid.toString(), JSON.stringify(urls.map(addOrigin))); +export async function playVideo(photo: IPhoto, urls: string[]) { + const auid = photo.auid ?? photo.fileid; + nativex?.playVideo?.(auid.toString(), photo.fileid.toString(), JSON.stringify(urls.map(addOrigin))); } /** * Destroy the video player. */ -export async function destroyVideo(fileId: number) { - nativex?.destroyVideo?.(fileId.toString()); +export async function destroyVideo(photo: IPhoto) { + nativex?.destroyVideo?.(photo.fileid.toString()); } /**