diff --git a/configs/e2e/native_dependencies.json b/configs/e2e/native_dependencies.json index a024e3337..2b68899f3 100644 --- a/configs/e2e/native_dependencies.json +++ b/configs/e2e/native_dependencies.json @@ -17,5 +17,6 @@ "react-native-image-picker": "7.2.3", "react-native-permissions": "5.5.1", "react-native-webview": "13.16.1", - "@sbaiahmed1/react-native-biometrics": "0.15.0" + "@sbaiahmed1/react-native-biometrics": "0.15.0", + "react-native-sound": "0.13.0" } diff --git a/package.json b/package.json index e4f4a6417..51b09d52d 100644 --- a/package.json +++ b/package.json @@ -105,8 +105,7 @@ "@mendix/pluggable-widgets-tools@11.8.0": "patches/@mendix+pluggable-widgets-tools+11.8.0.patch", "react-native-gesture-handler@2.31.2": "patches/react-native-gesture-handler+2.31.2.patch", "react-native-slider@0.11.0": "patches/react-native-slider+0.11.0.patch", - "react-native-snap-carousel@3.9.1": "patches/react-native-snap-carousel+3.9.1.patch", - "react-native-track-player@4.1.2": "patches/react-native-track-player@4.1.2.patch" + "react-native-snap-carousel@3.9.1": "patches/react-native-snap-carousel+3.9.1.patch" } }, "packageManager": "pnpm@10.32.0+sha512.9b2634bb3fed5601c33633f2d92593f506270a3963b8c51d2b2d6a828da615ce4e9deebef9614ccebbc13ac8d3c0f9c9ccceb583c69c8578436fa477dbb20d70" diff --git a/packages/jsActions/mobile-resources-native/package.json b/packages/jsActions/mobile-resources-native/package.json index 3b7e79be0..9656c53c4 100644 --- a/packages/jsActions/mobile-resources-native/package.json +++ b/packages/jsActions/mobile-resources-native/package.json @@ -41,7 +41,7 @@ "react-native-image-picker": "7.2.3", "react-native-localize": "3.7.0", "react-native-permissions": "5.5.1", - "react-native-track-player": "4.1.2", + "react-native-sound": "0.13.0", "url-parse": "^1.4.7" }, "devDependencies": { diff --git a/packages/jsActions/mobile-resources-native/src/platform/PlaySound.ts b/packages/jsActions/mobile-resources-native/src/platform/PlaySound.ts index dad9141c6..517473a58 100644 --- a/packages/jsActions/mobile-resources-native/src/platform/PlaySound.ts +++ b/packages/jsActions/mobile-resources-native/src/platform/PlaySound.ts @@ -5,7 +5,7 @@ // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. -import TrackPlayer, { State, Event } from "react-native-track-player"; +import Sound from "react-native-sound"; // BEGIN EXTRA CODE // END EXTRA CODE @@ -19,7 +19,7 @@ import TrackPlayer, { State, Event } from "react-native-track-player"; */ export async function PlaySound(audioFile?: mendix.lib.MxObject): Promise { // BEGIN USER CODE - // Documentation https://rntp.dev + // Documentation https://github.com/zmxv/react-native-sound if (!audioFile) { return Promise.reject(new Error("Input parameter 'Audio file' is required")); @@ -35,33 +35,22 @@ export async function PlaySound(audioFile?: mendix.lib.MxObject): Promise try { const url = await mx.data.getDocumentUrl(guid, changedDate); - // Initialize the player if it hasn't been set up yet - const state = await TrackPlayer.getPlaybackState(); - if (state.state === State.None) { - await TrackPlayer.setupPlayer({ - maxCacheSize: 1024 - }); - } - - await TrackPlayer.reset(); - await TrackPlayer.add({ - id: guid, - url, - title: `Audio ${guid}`, - artist: "Mendix App" - }); - await TrackPlayer.play(); - - return new Promise((resolve, reject) => { - const subscription = TrackPlayer.addEventListener(Event.PlaybackState, event => { - if (event.state === State.Stopped || event.state === State.Ended) { - subscription.remove(); - resolve(); - } else if (event.state === State.Error) { - subscription.remove(); - reject(new Error(event.error.message || "Playback error")); + return await new Promise((resolve, reject) => { + const sound = new Sound(url, "", error => { + if (error) { + reject(new Error(`Failed to load audio: ${error.message ?? error}`)); + return; } + + sound.play(success => { + sound.release(); + if (success) { + resolve(); + } else { + reject(new Error("Playback failed due to an audio encoding error")); + } + }); }); }); } catch (error) { diff --git a/patches/react-native-track-player@4.1.2.patch b/patches/react-native-track-player@4.1.2.patch deleted file mode 100644 index b82d32cf3..000000000 --- a/patches/react-native-track-player@4.1.2.patch +++ /dev/null @@ -1,28 +0,0 @@ -diff --git a/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt b/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt -index b2409a09939164c49c0f7a16bb6d3284e8eab8fb..699a6e4f4e2652eca69cd1d3a522c21971fee1b4 100644 ---- a/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt -+++ b/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt -@@ -545,7 +545,7 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM - if (verifyServiceBoundOrReject(callback)) return@launch - - if (index >= 0 && index < musicService.tracks.size) { -- callback.resolve(Arguments.fromBundle(musicService.tracks[index].originalItem)) -+ callback.resolve(musicService.tracks[index].originalItem?.let { Arguments.fromBundle(it) }) - } else { - callback.resolve(null) - } -@@ -584,9 +584,11 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM - if (verifyServiceBoundOrReject(callback)) return@launch - callback.resolve( - if (musicService.tracks.isEmpty()) null -- else Arguments.fromBundle( -- musicService.tracks[musicService.getCurrentTrackIndex()].originalItem -- ) -+ else musicService.tracks[musicService.getCurrentTrackIndex()].originalItem?.let { -+ Arguments.fromBundle( -+ it -+ ) -+ } - ) - } - diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ff3a365ce..f8d5c6189 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,9 +41,6 @@ patchedDependencies: react-native-snap-carousel@3.9.1: hash: 3a4c1b0f17629becc5d99ef1958df5a2f55c46e45f45670862aaeda12ab2f4e1 path: patches/react-native-snap-carousel+3.9.1.patch - react-native-track-player@4.1.2: - hash: 530fb9e20337a03d6000b7812e3a86cd1d266394959cc8dd59767410c3a83c4c - path: patches/react-native-track-player@4.1.2.patch importers: @@ -169,9 +166,9 @@ importers: react-native-permissions: specifier: 5.5.1 version: 5.5.1(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7))(@types/react@19.2.16)(react@19.2.3))(react@19.2.3) - react-native-track-player: - specifier: 4.1.2 - version: 4.1.2(patch_hash=530fb9e20337a03d6000b7812e3a86cd1d266394959cc8dd59767410c3a83c4c)(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7))(@types/react@19.2.16)(react@19.2.3))(react@19.2.3) + react-native-sound: + specifier: 0.13.0 + version: 0.13.0(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7))(@types/react@19.2.16)(react@19.2.3))(react@19.2.3) url-parse: specifier: ^1.4.7 version: 1.5.10 @@ -6156,24 +6153,17 @@ packages: react: 19.2.3 react-native: 0.84.1 - react-native-svg@15.15.4: - resolution: {integrity: sha512-boT/vIRgj6zZKBpfTPJJiYWMbZE9duBMOwPK6kCSTgxsS947IFMOq9OgIFkpWZTB7t229H24pDRkh3W9ZK/J1A==} + react-native-sound@0.13.0: + resolution: {integrity: sha512-SnREzaV0fmpYNuDV1Y8M7FutmaYei0pKBgpldULKKJMkoA3DBv5ppyRxY+oxRQ7HwEpt6LsonrKgM+13GH/tCw==} peerDependencies: react: 19.2.3 react-native: 0.84.1 - react-native-track-player@4.1.2: - resolution: {integrity: sha512-cIgMlqVJx/95hirUWPRW8CHxiBFj9Rjl/voKHh2jF/2URYMTQyt76t/m2FKvjeYUW2doKv4QSCBIOUmtyDLtJw==} + react-native-svg@15.15.4: + resolution: {integrity: sha512-boT/vIRgj6zZKBpfTPJJiYWMbZE9duBMOwPK6kCSTgxsS947IFMOq9OgIFkpWZTB7t229H24pDRkh3W9ZK/J1A==} peerDependencies: react: 19.2.3 react-native: 0.84.1 - react-native-windows: '>=0.63.0' - shaka-player: ^4.7.9 - peerDependenciesMeta: - react-native-windows: - optional: true - shaka-player: - optional: true react-native-video@6.19.2: resolution: {integrity: sha512-gh5dBMGSHywKr8+p4azRXrFQgT+QTmS1tI4sz6kVRjSENORfsrGGLQzmyo/7S9m+ZOTLWQJ3h8ONaXxR4F2Fcw==} @@ -13956,18 +13946,18 @@ snapshots: react-addons-shallow-compare: 15.6.2 react-native: 0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7))(@types/react@19.2.16)(react@19.2.3) - react-native-svg@15.15.4(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7))(@types/react@19.2.16)(react@19.2.3))(react@19.2.3): + react-native-sound@0.13.0(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7))(@types/react@19.2.16)(react@19.2.3))(react@19.2.3): dependencies: - css-select: 5.2.2 - css-tree: 1.1.3 react: 19.2.3 react-native: 0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7))(@types/react@19.2.16)(react@19.2.3) - warn-once: 0.1.1 - react-native-track-player@4.1.2(patch_hash=530fb9e20337a03d6000b7812e3a86cd1d266394959cc8dd59767410c3a83c4c)(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7))(@types/react@19.2.16)(react@19.2.3))(react@19.2.3): + react-native-svg@15.15.4(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7))(@types/react@19.2.16)(react@19.2.3))(react@19.2.3): dependencies: + css-select: 5.2.2 + css-tree: 1.1.3 react: 19.2.3 react-native: 0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7))(@types/react@19.2.16)(react@19.2.3) + warn-once: 0.1.1 react-native-video@6.19.2(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.85.3(@babel/core@7.29.7))(@types/react@19.2.16)(react@19.2.3))(react@19.2.3): dependencies: