React-native-track-player: SeekTo restarts track

Created on 22 Apr 2019  Â·  16Comments  Â·  Source: react-native-kit/react-native-track-player

So seekTo is restarting my audio to 0. When I am calling current position it is also 0. However ProgressComponents position is not 0.

Android

Most helpful comment

What we have figured out is that seeking, at least right after calling .play() needs to be different for each platform.

On Android you can just call them after each other:

await TrackPlayer.play();
await TrackPlayer.seekTo(whatever);

On iOS however, this won't work, it will always play from the start, so use an Event Listener:

    TrackPlayer.addEventListener('playback-state', async (stateObject) => {
        if (stateObject.state === TrackPlayer.STATE_PLAYING ) {
            await TrackPlayer.seekTo(snippet.start);
        }
    });
    await TrackPlayer.play();

All 16 comments

Which platform?

Android natively running @Guichaguri

I want add that when I am using async/await syntax position is ok, however in terms of Promise by then and catch it is 0. Also my duration is 0, despite of I added it by my self at trackinfo. Could it be because of duration is 0?
@Guichaguri

Tell me more about the track. It is from the network? If it is, does the server accepts range requests?

@Guichaguri ok, so it is on my laptop, and I just requiring it in url as in example at Getting started.

Can you upload the file somewhere so I can take a look?

@Guichaguri Have you opened and tested?

@Guichaguri Have you had a chance to look into this issue? I'm also experiencing this. The tracks we use are from a server, however seeking on iOS works fine.

seekTo does not work in android, i use the track from the example folder

https://drive.google.com/uc?export=download&id=1AjPwylDJgR8DOnmJWeRgZzjsohi-7ekj

I am facing the same for one week now. I am playing the track from the bundle. TrackPlayer.getPosistion() return 0 after a call to seekTo.
Does anyone find a solution to this problem ?

What we have figured out is that seeking, at least right after calling .play() needs to be different for each platform.

On Android you can just call them after each other:

await TrackPlayer.play();
await TrackPlayer.seekTo(whatever);

On iOS however, this won't work, it will always play from the start, so use an Event Listener:

    TrackPlayer.addEventListener('playback-state', async (stateObject) => {
        if (stateObject.state === TrackPlayer.STATE_PLAYING ) {
            await TrackPlayer.seekTo(snippet.start);
        }
    });
    await TrackPlayer.play();

Thanks

On Tue, Dec 10, 2019, 4:13 PM Felix notifications@github.com wrote:

What we have figured out is that seeking, at least right after calling
.play() needs to be different for each platform.

On Android you can just call them after each other:

await TrackPlayer.play();
await TrackPlayer.seekTo(whatever);

On iOS however, this won't work, it will always play from the start, so
use an Event Listener:

TrackPlayer.addEventListener('playback-state', async (stateObject) => {
if (stateObject.state === TrackPlayer.STATE_PLAYING ) {
await TrackPlayer.seekTo(snippet.start);
}
});
await TrackPlayer.play();

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/react-native-kit/react-native-track-player/issues/558?email_source=notifications&email_token=ALPZVOJ5CYL4V7FCGOXYMFTQX65ZRA5CNFSM4HHQZ3V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGPZUMI#issuecomment-564107825,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ALPZVOJGIH6WRUEGVT6CMNLQX65ZRANCNFSM4HHQZ3VQ
.

The original issue seems to be related to unseekable tracks.

The latter one will be fixed by #713

Hi everyone,

unfortunately the solution provided by @fritzfr does not work for me, because I experience the problem on android and not on iOS.

I am trying to implement the jump backward/jump forward functionality. In my service I registered:

TrackPlayer.addEventListener('remote-jump-backward', (data) => {
    let seconds = data.interval ? data.interval : data // on Ios I get the seconds, while on android i get an object with the interval property
    console.log('backward', seconds)
    TrackPlayer.getPosition().then((current) => {
      console.log('current position', current)
      console.log('seeking to', Math.round(current) - seconds)
      TrackPlayer.seekTo(Math.round(current) - seconds)
        .then(() => console.log('seeked properly'))
        .catch((err) => console.warn('error seeking', err))
    })
  })

When I press the jump backward button on Android, the logs are correct:

LOG backward 10
LOG current position 16.118
LOG seeking to 6
LOG seeked properly

But the track starts again from 0, instead of the selected seconds (6 in the example). The same track and the same method on iOS works perfectly

Is there a work around for this problem? The developers should come up with something for us cause seeking is an important feature in a player.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ManrickCapotolan picture ManrickCapotolan  Â·  4Comments

Sathyanarayan09 picture Sathyanarayan09  Â·  3Comments

JakeMotta picture JakeMotta  Â·  3Comments

moduval picture moduval  Â·  3Comments

b3rkaydem1r picture b3rkaydem1r  Â·  3Comments