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.18k stars 981 forks source link

RCTJSONStringify() encountered the following error: Invalid number value (NaN) in JSON write #2204

Closed Gurupatic closed 3 months ago

Gurupatic commented 7 months ago

Describe the Bug

Adding a track with a path to a local file causes an error

https://github.com/doublesymmetry/react-native-track-player/assets/151741365/27200023-4664-4c83-9d29-433f6fca042b

 {
        id: 4,
        url: require('./src/assets/audio/test.mp3'),
        title: 'track 4',
 }

Steps To Reproduce configure TrackPlayer and call this function by replacing the path to the local file with your own path

const addTracks = async () => {
    const list = [
      {
        id: 1,
        url: 'https://www.kozco.com/tech/organfinale.mp3',
        title: 'track 1',
      },
      {
        id: 2,
        url: 'https://www.kozco.com/tech/piano2-CoolEdit.mp3',
        title: 'track 2',
      },
      {
        id: 3,
        url: 'https://www.kozco.com/tech/WAV-MP3.wav',
        title: 'track 3',
      },
      {
        id: 4,
        url: require('./src/assets/audio/test.mp3'),
        title: 'track 4',
      },
    ]
    try {
      TrackPlayer.add(list)
      setTracks(list)
    } catch (e: any) {
      console.error(e)
    }
  }

Code To Reproduce Please provide a simple code example that allows others to replicate the bug.

Environment Info: IOS simulator TrackPlayer 4.0.1

System:
  OS: macOS 14.1.1
  CPU: (8) arm64 Apple M1 Pro
  Memory: 64.70 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 21.1.0
    path: ~/.nvm/versions/node/v21.1.0/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.0
    path: ~/.nvm/versions/node/v21.1.0/bin/npm
  Watchman:
    version: 2023.10.23.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.0
    path: /usr/local/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.11005911
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.19
    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.1
    wanted: 0.72.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: false
  newArchEnabled: false
lovegaoshi commented 7 months ago

i think that just means your relative file location is not found (require should return a number ? but returned a NaN ?) if thats not the case u can copy how example does it https://github.com/doublesymmetry/react-native-track-player/blob/main/example/src/services/QueueInitialTracksService.ts

mitchdowney commented 7 months ago

I just ran into this error too using RNTP 4.0.1 with Xcode v15.0.1 (15A507) and iOS Simulator 15 Pro Max...when I inspect the track in PlaybackActiveTrackChanged I see the following url:

https://aphid.fireside.fm/d/1437767933/f31a453c-fa15-491f-8618-3f71f1d565e5/875cb013-cea4-481b-b5b5-b060249474af.mp3

So it appears the issue is happening even with a remote track for me?

The error only seems to get thrown when I have "Debug with Chrome" turned on. If I dismiss the error, RNTP still seems to play the audio correctly.

NiharR27 commented 6 months ago

+1 facing same issue with Debugger turned on

github-actions[bot] commented 3 months ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 3 months ago

This issue was closed because it has been stalled for 7 days with no activity.

ahaseeb001 commented 1 month ago

code const AppAudio = { starting: require("../../../../assets/audio/listenStartTone.wav"), };

const Track = { url: AppAudio.starting, title: "Noonan Welcome", artist: "Noonan Bot", artwork: "Noonan", };

const WelcomeVoiceNoteHandler = async () => { try { await TrackPlayer.reset(); await TrackPlayer.add(Track); await TrackPlayer.play(); } catch (e) { console.log("🚀 🚀 ~ WelcomeVoiceNoteHandler ~ e:", e); } };

useEffect(() => { WelcomeVoiceNoteHandler(); }, []);

Error simulator_screenshot_25B31C08-2D8D-4292-9FDA-1C367FE0F7C0