nx: force local video when available

Signed-off-by: Varun Patil <radialapps@gmail.com>
dexie
Varun Patil 2023-09-30 14:14:36 -07:00
parent 0b745fef6f
commit 96e033b23d
2 changed files with 17 additions and 30 deletions

View File

@ -138,17 +138,12 @@ class VideoContentSetup {
// Hand off to native player if available // Hand off to native player if available
if (nativex.has()) { if (nativex.has()) {
const fileid = content.data.photo.fileid;
// Local videos are played back directly // Local videos are played back directly
if (utils.isLocalPhoto(content.data.photo)) { // Remote videos are played back via HLS / Direct
nativex.playVideoLocal(fileid); nativex.playVideo(
return; content.data.photo,
} sources.map((s) => s.src)
);
// Use both remote sources
const urls = sources.map((s) => s.src);
nativex.playVideoRemote(fileid, urls);
return; return;
} }
@ -259,7 +254,7 @@ class VideoContentSetup {
// Add a timeout in case another video initializes // Add a timeout in case another video initializes
// immediately after this one is destroyed // immediately after this one is destroyed
setTimeout(() => { setTimeout(() => {
nativex.destroyVideo(content.data.photo.fileid); nativex.destroyVideo(content.data.photo);
}, 500); }, 500);
} }

View File

@ -126,18 +126,14 @@ export type NativeX = {
downloadFromUrl: (url: string, filename: string) => void; downloadFromUrl: (url: string, filename: string) => void;
/** /**
* Play a video from the given file ID (local file). * Play a video from the given AUID or URL(s).
* @param fileid File ID of the video * @param auid AUID of file (will play local if available)
*/ * @param fileid File ID of the video (only used for file tracking)
playVideoLocal: (fileid: string) => void;
/**
* Play a video from the given URL(s).
* @param fileid Remote file ID of the video (used for play tracking)
* @param urlArray JSON-encoded array of URLs to play * @param urlArray JSON-encoded array of URLs to play
* @details The URL array may contain multiple URLs, e.g. direct playback * @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. * 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. * Destroy the video player.
* @param fileid File ID of the video * @param fileid File ID of the video
@ -224,25 +220,21 @@ export async function playTouchSound() {
nativex?.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. * 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[]) { export async function playVideo(photo: IPhoto, urls: string[]) {
nativex?.playVideoRemote?.(fileid.toString(), JSON.stringify(urls.map(addOrigin))); const auid = photo.auid ?? photo.fileid;
nativex?.playVideo?.(auid.toString(), photo.fileid.toString(), JSON.stringify(urls.map(addOrigin)));
} }
/** /**
* Destroy the video player. * Destroy the video player.
*/ */
export async function destroyVideo(fileId: number) { export async function destroyVideo(photo: IPhoto) {
nativex?.destroyVideo?.(fileId.toString()); nativex?.destroyVideo?.(photo.fileid.toString());
} }
/** /**