React-native-track-player: seekTo on android restart track - impossible to jump forward/backword

Created on 26 Jun 2020  路  10Comments  路  Source: react-native-kit/react-native-track-player

Hi everyone,
I found the issue #558 but it refers to an old version of the library and has been closed, so I decided to open a new issue.

First of all, thank you for the amazing library.

The bug: seekTo on an mp3 file on android restart the track.

Details:

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.

I got this error on version 1.2.3. I tried to upgrade to 2.0.0-rc13 with the same result.

Bug Needs Confirmation

Most helpful comment

I think it's related to the mp3 format. I converted my files to m4a using ffmpeg and everything works perfectly.

In case anyone is interested, here is the command I used to convert the files:

ffmpeg  -i input.mp3 -c:a libfdk_aac -vbr 4 -vn output.m4a

All 10 comments

I am using v2.0.0-rc13 and facing the same issue.

Same here:

"react": "16.11.0", "react-native": "0.62.2", "react-native-track-player": "^1.2.3"

Can you send us the URL or the file you're playing so we can reproduce the bug?

I'm facing the same problem on Android only.

"react": "16.11.0", "react-native": "0.62.2", "react-native-track-player": "^1.2.3",

I'm reproducing the same files (URL) provided in the example app.

  const playlistData = [
    {
      id: '1111',
      url:
        'https://drive.google.com/uc?export=download&id=1AjPwylDJgR8DOnmJWeRgZzjsohi-7ekj',
      title: 'Longing',
      artist: 'David Chavez',
      artwork: 'https://i.picsum.photos/id/100/200/200.jpg',
      duration: 143,
    },
    {
      id: '2222',
      url:
        'https://drive.google.com/uc?export=download&id=1VM9_umeyzJn0v1pRzR1BSm9y3IhZ3c0E',
      title: 'Soul Searching (Demo)',
      artist: 'David Chavez',
      artwork: 'https://i.picsum.photos/id/200/200/200.jpg',
      duration: 77,
    },
    {
      id: '3333',
      url:
        'https://drive.google.com/uc?export=download&id=1bmvPOy2IVbkUROgm0dqiZry_miiL4OqI',
      title: 'Lullaby (Demo)',
      artist: 'David Chavez',
      artwork: 'https://i.picsum.photos/id/300/200/200.jpg',
      duration: 71,
    },
    {
      id: '4444',
      url:
        'https://drive.google.com/uc?export=download&id=1V-c_WmanMA9i5BwfkmTs-605BQDsfyzC',
      title: 'Rhythm City (Demo)',
      artist: 'David Chavez',
      artwork: 'https://i.picsum.photos/id/400/200/200.jpg',
      duration: 106,
    },
  ]

My both functions jumpForward and jumpBackward that use seekTo set the track to position 0.

  async function jumpForward() {
    console.log('Jump forward')
    const offset = 10
    try {
      const position = await TrackPlayer.getPosition()
      const duration = await TrackPlayer.getDuration()

      console.log({position, duration})

      if (duration - position > offset) {
        console.log('jumping in fact')
        await TrackPlayer.seekTo(position + offset)
      }
    } catch (err) {
      console.log(err)
    }
  }

  async function jumpBackward() {
    const offset = 10
    console.log('Jump backward')
    try {
      const position = await TrackPlayer.getPosition()
      if (position - offset > 0) {
        await TrackPlayer.seekTo(position - offset)
      } else {
        await TrackPlayer.seekTo(0)
      }
    } catch (err) {
      console.log(err)
    }
  }

Any help is really appreciated.

UPDATE

Debugging a little deeper, I realized that my position value, which I get from await TrackPlayer.getPosition() is returning 0 (zero) every time. I assume it's not correct since the audio is being reproduced loud and clear. Maybe this piece of information may help us discover what's going on.

I think it's related to the mp3 format. I converted my files to m4a using ffmpeg and everything works perfectly.

In case anyone is interested, here is the command I used to convert the files:

ffmpeg  -i input.mp3 -c:a libfdk_aac -vbr 4 -vn output.m4a

@gbalduzzi You might be right. I converted the same mp3 files (using ffmpeg) into m4a and it did work. Thanks for your response!

I face the same issue but I can't convert the mp3 files (I do not control the audio content).
So is this issue being addressed?

I think it's related to the mp3 format. I converted my files to m4a using ffmpeg and everything works perfectly.

In case anyone is interested, here is the command I used to convert the files:

ffmpeg  -i input.mp3 -c:a libfdk_aac -vbr 4 -vn output.m4a

It works, both on IOS and Android

I have the same problem, and converting mp3 to m4a works 馃憤

But this is only a workaround. Looking forward to a proper fix.

+1

Was this page helpful?
0 / 5 - 0 ratings