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

Duplicate tracks added to the TrackPlayer queue after the app is refreshed in a dev environment #2201

Closed Nikitas-io closed 10 months ago

Nikitas-io commented 10 months ago

The Bug When I refresh my app by pressing the R key on my console, the already existing tracks are added as duplicates to the TrackPlayer queue.

Steps To Reproduce This issue does NOT occur if the user closes the app and then opens it back up again. It specifically occurs when the app is refreshed through the console in a development environment. To reproduce the issue you can refresh the app by pressing the R key in your console, and after the app is done refreshing, load your tracks to the queue.

If for example I have 7 tracks in my queue, then refresh the app by pressing the 'r' key on my terminal, my queue will then look like this:

 LOG  • Existing track with index:  1
 LOG  • Existing track with index:  2
 LOG  • Existing track with index:  3
 LOG  • Existing track with index:  4
 LOG  • Existing track with index:  5
 LOG  • Existing track with index:  6
 LOG  • Existing track with index:  7
 LOG  • Existing track with index:  8 (duplicate of track with index 1)
 LOG  • Existing track with index:  9 (duplicate of track with index 2)
 LOG  • Existing track with index:  10 (duplicate of track with index 3)
 LOG  • Existing track with index:  11 (duplicate of track with index 4)
 LOG  • Existing track with index:  12 (duplicate of track with index 5)
 LOG  • Existing track with index:  13 (duplicate of track with index 6)
 LOG  • Existing track with index:  14 (duplicate of track with index 7)

The existing articles will then be tripled in the same manner if I refresh the app once more and add yet another track to the queue, and so on.

Environment Info: The results of npx react-native info:

System:
  OS: macOS 13.6
  CPU: (8) arm64 Apple M2
  Memory: 152.22 MB / 8.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.5.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 9.8.1
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2023.08.07.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10406996
  Xcode:
    version: 15.0/15A240d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.20
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.4
    wanted: ^0.72.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

The react-native-track-player version I am using:

"react-native-track-player": "^4.0.1",

• I am using a real Android device though the issue is probably everywhere • I am running Android version 11 RP1A.200720.011

Nikitas-io commented 10 months ago

So it seems that if I reset the TrackPlayer using the reset() method after the app is refreshed and before the tracks are loaded to the player again, then the issue goes away.