From 13d51e2424dda214bccd0f4700055f032f2b9765 Mon Sep 17 00:00:00 2001 From: Rolf Loges Date: Thu, 29 Jan 2026 13:33:58 +0100 Subject: [PATCH] fix: also pass the loop video option on the native player Signed-off-by: Rolf Loges --- .../src/main/java/gallery/memories/MainActivity.kt | 5 ++++- .../app/src/main/java/gallery/memories/NativeX.kt | 9 +++++++-- src/native/api.ts | 12 ++++++++++++ src/native/video.ts | 8 +++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/java/gallery/memories/MainActivity.kt b/android/app/src/main/java/gallery/memories/MainActivity.kt index 09b2195fa..473ddacd5 100644 --- a/android/app/src/main/java/gallery/memories/MainActivity.kt +++ b/android/app/src/main/java/gallery/memories/MainActivity.kt @@ -338,7 +338,7 @@ class MainActivity : AppCompatActivity() { return false } - fun initializePlayer(uris: Array, uid: Long) { + fun initializePlayer(uris: Array, uid: Long, loop: Boolean = false) { if (player != null) { if (playerUid == uid) return player?.release() @@ -403,6 +403,9 @@ class MainActivity : AppCompatActivity() { } }) + + exoPlayer.repeatMode = if (loop) Player.REPEAT_MODE_ONE else Player.REPEAT_MODE_OFF + // Start the player exoPlayer.playWhenReady = playWhenReady exoPlayer.prepare() diff --git a/android/app/src/main/java/gallery/memories/NativeX.kt b/android/app/src/main/java/gallery/memories/NativeX.kt index 96f09427f..f924e3f5d 100644 --- a/android/app/src/main/java/gallery/memories/NativeX.kt +++ b/android/app/src/main/java/gallery/memories/NativeX.kt @@ -119,6 +119,11 @@ class NativeX(private val mCtx: MainActivity) { @JavascriptInterface fun playVideo(auid: String, fileid: Long, urlsArray: String) { + this.playVideo2(auid, fileid, urlsArray, false) + } + + @JavascriptInterface + fun playVideo2(auid: String, fileid: Long, urlsArray: String, loop: Boolean = false) { mCtx.threadPool.submit { // Get URI of remote videos val urls = JSONArray(urlsArray) @@ -132,9 +137,9 @@ class NativeX(private val mCtx: MainActivity) { // Play with exoplayer mCtx.runOnUiThread { if (!videos.isEmpty()) { - mCtx.initializePlayer(arrayOf(videos[0].uri), fileid) + mCtx.initializePlayer(arrayOf(videos[0].uri), fileid, loop) } else { - mCtx.initializePlayer(list, fileid) + mCtx.initializePlayer(list, fileid, loop) } } } diff --git a/src/native/api.ts b/src/native/api.ts index 0f1a46063..c7b7dc71c 100644 --- a/src/native/api.ts +++ b/src/native/api.ts @@ -140,6 +140,7 @@ export type NativeX = { setShareBlobs: (objects: string) => void; /** + * This signature is kept for backward compatibility. * 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) @@ -149,6 +150,17 @@ export type NativeX = { */ playVideo: (auid: string, fileid: number, urlArray: string) => void; + /** + * 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 + * @param loop Whether the video should loop + * @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. + */ + playVideo2: (auid: string, fileid: number, urlArray: string, loop?: boolean) => void; + /** * Destroy the video player. * @param fileid File ID of the video diff --git a/src/native/video.ts b/src/native/video.ts index 9f7fb1524..68ac28e0d 100644 --- a/src/native/video.ts +++ b/src/native/video.ts @@ -1,5 +1,6 @@ import { nativex } from './api'; import { addOrigin } from './basic'; +import staticConfig from '@services/static-config'; import type { IPhoto } from '@typings'; /** @@ -8,7 +9,12 @@ import type { IPhoto } from '@typings'; * @param urls URLs to play (remote) */ export async function playVideo(photo: IPhoto, urls: string[]) { - nativex?.playVideo?.(photo.auid ?? String(), photo.fileid, JSON.stringify(urls.map(addOrigin))); + const loop = staticConfig.getSync('video_loop') || false; + if (typeof nativex?.playVideo2 === 'function') { + nativex?.playVideo2?.(photo.auid ?? String(), photo.fileid, JSON.stringify(urls.map(addOrigin)), loop); + } else { + nativex?.playVideo?.(photo.auid ?? String(), photo.fileid, JSON.stringify(urls.map(addOrigin))); + } } /**