doublesymmetry / react-native-track-player

A fully fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!
https://rntp.dev/
Apache License 2.0
3.2k stars 984 forks source link

Repeat does not work on real device #2141

Closed jaikantshikray closed 9 months ago

jaikantshikray commented 10 months ago

The Track does not repeat on real device IOS and it struck between the states of pause and play and keeps showing pause and play state.

Steps To Reproduce

Downloaded the sound from server and saved in document directory and starts playing the sound when the sound completes it does not restart even with Repeat Mode.

Code To Reproduce

RNFetchBlob .config({ // response data will be saved to this path if it has access right. path: dirs.DocumentDir + '/' + item.name + '.mp3', fileCache: true, }) .fetch('GET', url, { //some headers .. }) .then(async (res) => { console.log("resds", res) // the path should be dirs.DocumentDir + 'path-to-file.anything' console.log('The file saved to ', res.path()) var track1 = { url: res.path(), // Load media from the network title: item.name, artist: '', album: '', genre: '****', date: '2014-05-20T07:00:00+00:00', // RFC 3339 artwork: '', // Load artwork from the network duration: item.duration // Duration in seconds }; await TrackPlayer.add([track1]); await TrackPlayer.setRepeatMode(RepeatMode.Track); TrackPlayer.play().then(() => { console.log("play started") }).catch(er => { console.log("err is ", er); }); }).catch(err => { console.log("err", err); });

Replicable on Example App?

copied the exact callbacks from example app

Environment Info: react-native: 0.73.9 react-native-track-player: 3.2.0 Real device IOS

image
Ritikchhipa5 commented 10 months ago

Yes same issue , I also facing

dcvz commented 9 months ago

@jaikantshikray @Ritikchhipa5 are you both on v3.2? Are you about to try the V4 RC's?

Ritikchhipa5 commented 9 months ago

Yes, I try but the same issue is happening. But the thing is why is not working in the real device and when run why it will take a lot of memory?

jaikantshikray commented 9 months ago

it does not work with the latest version on real device works fine on simulator although

jimluo123 commented 9 months ago

I met this problem on my iOS simulator. I used this version.

"react-native-track-player": "^4.0.0-rc09",
Ritikchhipa5 commented 9 months ago

same version I use its works in iOS simulator but not in real device .

dcvz commented 9 months ago

I cannot seem to experience this using the latest RC and on physical device in release mode. Could one of you perhaps share one of the tracks you're seeing issues with? Would also be helpful if you could tell me the iOS device you're testing with.

jimluo123 commented 9 months ago

I met this problem on my iOS simulator. I used this version.

"react-native-track-player": "^4.0.0-rc09",

When I used a physical device, the repeat mode worked. My physical device is an iPhone X

rvmoldova commented 9 months ago
Nevermind, app was crashing because of BOOM (Background Out of memory) I have the same issue. The most interesting part is that before it worked perfectly, but I tried older builds (with RC05–08) and the issue still persists. I noticed that some tracks loop more times, others just 1-2 times. Also, I noticed on the simulator that "useProgress().duration" reports a little shorter duration. E.g., 30 sec track: on simulator: `29.999333`, on real device: `30.001`, actual duration: `29.996`. I'm not sure if this finding is valuable; I'm just leaving it here just in case. (thus simulator readings are more close to actual duration) ![CleanShot 2023-10-11 at 11  26 04](https://github.com/doublesymmetry/react-native-track-player/assets/13289513/8d0ee51d-20a1-4b2d-ba33-8aecf06b2851) ![IMG_0014](https://github.com/doublesymmetry/react-native-track-player/assets/13289513/e5783c18-3b2c-4a5b-a210-5ad53ef44f6c) ![CleanShot 2023-10-11 at 11  40 51](https://github.com/doublesymmetry/react-native-track-player/assets/13289513/40d94322-c2aa-41d2-bc15-8d8229dedbe3)
rvmoldova commented 9 months ago
Nevermind, app was crashing because of BOOM (Background Out of memory) Here is `white.m4a`, The issue is reproducible on several devices: iPad Pro 2021, iPhone SE 2020, iPhone 13 Pro Max, iPhone 14 Pro Max, and iPhone X. (basically every device) [white.m4a.zip](https://github.com/doublesymmetry/react-native-track-player/files/12866978/white.m4a.zip) btw: I also tried to do `play([track,track,track,track x 1000])` to force it to "repeat". But it stops after the 3–4th track. So I don't think it's related to `setRepeatMode`. Also tried `pure.m4a` from examples, same issue code snippets: ```ts ... await TrackPlayer.setupPlayer({ autoHandleInterruptions: true, iosCategory: IOSCategory.Playback, iosCategoryMode: IOSCategoryMode.Default, iosCategoryOptions: [ IOSCategoryOptions.AllowAirPlay, IOSCategoryOptions.AllowBluetooth, IOSCategoryOptions.AllowBluetoothA2DP, IOSCategoryOptions.DuckOthers, IOSCategoryOptions.MixWithOthers, ], androidAudioContentType: AndroidAudioContentType.Music }); ... // play: const play = async (tracks: Track[], repeat = true, noPause = false) => { await TrackPlayer.reset(); const capabilities = [ Capability.Play, Capability.Stop, ...(noPause ? [] : [ Capability.Pause, Capability.SeekTo ]), ...(repeat && tracks.length > 1 ? [ Capability.SkipToNext, Capability.SkipToPrevious, ] : [ Capability.JumpForward, Capability.JumpBackward, ]) ]; const compactCapabilities = [ Capability.Play, ...(noPause ? [] : [ Capability.Pause, Capability.SeekTo ]), ...(repeat && tracks.length > 1 ? [ Capability.SkipToNext, ] : []) ]; await TrackPlayer.updateOptions({ android: { appKilledPlaybackBehavior: AppKilledPlaybackBehavior.ContinuePlayback, }, capabilities, compactCapabilities, progressUpdateEventInterval: 1, forwardJumpInterval: 10, backwardJumpInterval: 10, }); await TrackPlayer.add(tracks); if (repeat) { await TrackPlayer.setRepeatMode(tracks.length > 1 ? RepeatMode.Queue : RepeatMode.Track); } else { await TrackPlayer.setRepeatMode(RepeatMode.Off); } await TrackPlayer.play(); }; ... ```
rvmoldova commented 9 months ago

@jaikantshikray as suggestion, check in xCode CPU and memory readings, when you put app into background. If they are increasing, then it could be you have a memory leak which can cause BOOMs

dcvz commented 9 months ago

Ok, looks like we have seen it works on device. I will go ahead and close this now.

mitchdowney commented 8 months ago

We recently added RepeatMode.Queue handling to Podverse, and I am running into this issue intermittently on my actual iPhone XR when listening to a short track, when it is the only track in the queue. It does not seem to happen when multiple tracks are in the queue. Also, I am unable to reproduce the issue with iOS Simulator.

I don't know if it's an RNTP issue for sure. I'm inserting and removing items from the queue after the current player item is loaded, so there is funkiness in our setup, and maybe the queue doesn't like that. Oddly though this issue seems to only happen when a single track is in the queue, and I shouldn't be doing funky add/remove to queue stuff for that.

mitchdowney commented 8 months ago

OOF. I am still on 4.0.0-rc04. It looks like a RepeatMode fix for iOS was added in #2070. Maybe we just need to upgrade.