Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion android/app/src/main/java/gallery/memories/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class MainActivity : AppCompatActivity() {
return false
}

fun initializePlayer(uris: Array<Uri>, uid: Long) {
fun initializePlayer(uris: Array<Uri>, uid: Long, loop: Boolean = false) {
if (player != null) {
if (playerUid == uid) return
player?.release()
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 7 additions & 2 deletions android/app/src/main/java/gallery/memories/NativeX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/native/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/native/video.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { nativex } from './api';
import { addOrigin } from './basic';
import staticConfig from '@services/static-config';
import type { IPhoto } from '@typings';

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

/**
Expand Down