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
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);
}

View File

@ -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());
}
/**