Is there any way to add a track to the queue without playing it? What I want to achieve is adding tracks one at a time to the queue and then playing them only when the play method is called.
Same question here
@minhtc That's not the point. The point is when you add a track, it shouldn't be automatically played. Adding a track to the player should only load the track and change the status to ready (or whatever the status should be). This is an obvious violation of SoC. Every function should be doing one and only one thing.
Which platform are you facing this issue?
@Guichaguri I'm having the issue in iOS. I haven't tried it in Android though. So, is this a bug or is it by design?
@Guichaguri I believe on Android we also have it to where adding the first track automatically plays it, no?
@dcvz In Android, it's a boolean property that defines if it will play or not that can be changed through play() or pause()
TrackPlayer.play(); // sets "play when ready" to true
TrackPlayer.add(...); // as soon as the track loads, it will start playing
TrackPlayer.pause(); // sets "play when ready" to false
TrackPlayer.add(...); // it will load the track, but not start it yet
@Guichaguri that's exactly what I believe should change. TrackPlayer.add(...); should only add the track and set the status to "ready".
it only happens in iOS. Does anyone have a solution for this?
I'm going to set it to "adding a track when there's no tracks in queue will not automatically start". You'll have to then call play(). /cc @Guichaguri
This is now fixed in: 31fd540278e463d0b9051fcc09886b71dd26ed8c
It works now. Thanks!
This also fixes some strange behavior if you are trying to start a track from a certain point such as:
await TrackPlayer.reset();
await TrackPlayer.add(track);
await TrackPlayer.seekTo(position);
await TrackPlayer.play();
Without this fix, sometimes this ends up with the track paused at the position, instead of playing.
For anyone wondering this landed right after 1.1.2 so presumably it will be ready in 1.1.3, although you can access it now by pointing to the dev branch
Hey, @dcvz it seems to me that TrackPlayer.add still triggers playback-track-changed event with nextTrack containing the id of the very first queue item. Is this still intended? Shouldn't it only get fired on play after adding tracks?
Most helpful comment
This is now fixed in: 31fd540278e463d0b9051fcc09886b71dd26ed8c