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.29k stars 1.01k forks source link

The duration and position are inconsistent with larger tracks(+1 hour). #1213

Closed edgargrs closed 3 years ago

edgargrs commented 3 years ago

Describe the bug First of all, thanks for this amazing library. 🙌

This only happens on android. iOS works well. If I use tracks longer than one hour the position exceeds the duration and the duration and position returned are inconsistent. I realized that if I started the track from beginning and let it run until the end this not happen. Only when I seek to a new position. It's very strange, if I seek to (seekTo) closer to the end, the difference is less than if I seek to a position less close to the end of the track. I'm testing with 7 different tracks loaded from network and in some cases the duration and position are inconsistent. I'm adding the duration in the track object add([]). Also my audios have 44.1 kHz of sample rate and they are MP3 files. I changed the build preferences for the app using many values in track-player.json

Results of my test:

const durations = [
  1177.3648979591837, // 19:36 - Works
  2420.1404081632654, // 40:19 - Works
  3549.126530612245, // 59:08 - Works
  3934.1975510204084, // 01:05:40 - Doesn't work
  4977.502040816326, // 1:24:56 - Doesn't work
  5415.758367346939, // 1:30:14 - Doesn't work
  8872.724, // 2:27:55 - Doesn't work
];

To Reproduce I create a repository to reproduce the issue 👉 https://gitlab.com/edgargrs/rntrackaudioplayerexample

Environment:

System:
    OS: macOS 11.2.2
    CPU: (8) arm64 Apple M1
    Memory: 130.89 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.0.0 - ~/.nvm/versions/node/v16.0.0/bin/node
    Yarn: 1.22.10 - /opt/homebrew/bin/yarn
    npm: 7.10.0 - ~/.nvm/versions/node/v16.0.0/bin/npm
    Watchman: 4.9.0 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK:
      API Levels: 22, 23, 25, 27, 28, 29, 30
      Build Tools: 23.0.3, 24.0.3, 25.0.3, 26.0.3, 27.0.3, 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3
      System Images: android-24 | Google APIs Intel x86 Atom, android-25 | Google APIs ARM 64 v8a, android-25 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom_64
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.7199119
    Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_242-release - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1 
    react-native: 0.64.2 => 0.64.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

What react-native-track-player version are you using? This happens on the plugin version: v2.0.0-rc18 and v1.2.7

In master branch I'm using v2.0.0-rc18 I created another branch with the version v1.2.7 and the same happens. v2.0.0-rc18 👉 https://gitlab.com/edgargrs/rntrackaudioplayerexample v1.2.7 👉 https://gitlab.com/edgargrs/rntrackaudioplayerexample/-/tree/v1.2.7

Probably related issues 983 963 860 629 228

edgargrs commented 3 years ago

After test another playback libraries, and a little research I realized that the problem was with the MP3s. it seems that the MP3 files are not inherently seekable.

https://stackoverflow.com/questions/53742145/precise-seek-in-mp3-files-on-android

I solved this problem by changing the MP3 for M4A format.