Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrackPlayer.getProgress() does not return duration on ios #2311

Open
LucasLfs2004 opened this issue May 14, 2024 · 2 comments
Open

TrackPlayer.getProgress() does not return duration on ios #2311

LucasLfs2004 opened this issue May 14, 2024 · 2 comments
Labels

Comments

@LucasLfs2004
Copy link

Describe the Bug
I'm trying to get the duration of mp3 audios from the internet, on android I get the duration of the audios normally, but on ios it always returns 0. I'm using TrackPlayer.getProgress() for both, but on ios it doesn't return the duration value.

Steps To Reproduce
Adding Tracks to TrackPlayer

use TrackPlayer.getProgress() to get the duration of the track.

Code To Reproduce

const track = {
  url: 'https://api.ahshow.tv/static/lists/performercard/16/audioe6e70037919f985856722fca65aae47f0426e3cfbc6d35c7ddcffedadcae7aee.mp3',
  title: 'Audio de 1',
  artist: 'John',
  artwork:
    '../cover.jpg',
};


  const getDurationFromTracks = async () => {
    const response = await TrackPlayer.setupPlayer();
    await TrackPlayer.add(track);
    const duration = await getProgress();
    console.log(duration)
  };

  const getProgress = async () => {
    const duration = await TrackPlayer.getProgress();

    if (duration > 0) {
      return duration.duration;
    }
    return await getProgress();
  };

No android criei a função getProgress para que quando o TrackPlayer tivesse o valor da duração, retornasse. Mas no ios o valor da duração sempre é 0.

Replicable on Example App?
Can you replicate this bug in the React Native Track Player Example App?

Environment Info:
npx react-native info

System:
OS: macOS 14.4.1
CPU: (10) arm64 Apple M2 Pro
Memory: 104.92 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 20.11.0
path: /usr/local/bin/node
Yarn:
version: 1.22.19
path: ~/.yarn/bin/yarn
npm:
version: 10.2.4
path: /usr/local/bin/npm
Watchman:
version: 2024.01.22.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.5
- iOS 17.5
- macOS 14.5
- tvOS 17.5
- visionOS 1.2
- watchOS 10.5
Android SDK: Not Found
IDEs:
Android Studio: 2023.1 AI-231.9392.1.2311.11255304
Xcode:
version: 15.4/15F31d
path: /usr/bin/xcodebuild
Languages:
Java:
version: 18.0.2
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.73.6
wanted: 0.73.6
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false

react-native-track-player version: 4.1.1

I'm using IOS simulator

How I can Help
Does anyone know how I can get the audio duration value on ios?

@yaroslav-vasilyev
Copy link

Same for android...Don't know what it is, but I solved it with TrackPlayer.getActiveTrack().duration

@lovegaoshi
Copy link
Contributor

pls launch the example app, find where this would work in the example app (eg. this would be useProgress in the progress bar component), then try ur url in the example app first. then u will likely deduce if its ur URL's problem, ur code bases problem, or RNTP's bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants