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

Duration value is always '0' in useProgress hooks #1709

Closed
kyimoemin opened this issue Sep 8, 2022 · 6 comments
Closed

Duration value is always '0' in useProgress hooks #1709

kyimoemin opened this issue Sep 8, 2022 · 6 comments

Comments

@kyimoemin
Copy link

Describe the Bug
the value of duration that returned from useProgress hooks is always '0' in iOS simulator. Android simulator don't have that problem, the duration is showing correctly in android.

Steps To Reproduce
start the iOS simulator and run the following code.

Code To Reproduce

const {position,buffered,duration} = useProgress();

console.log(position,buffered,duration);
/**
 the duration value is always 0,
e.g.,
 position:12
 duration:0
*/

Environment Info:

System:
OS: macOS 12.5.1
CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
Memory: 47.27 MB / 8.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 14.17.0 - /usr/local/bin/node
Yarn: Not Found
npm: 6.14.13 - /usr/local/bin/npm
Watchman: 2021.06.07.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK:
API Levels: 27, 28, 29, 30, 31
Build Tools: 29.0.2, 30.0.3, 31.0.0
System Images: android-29 | Intel x86 Atom, android-29 | Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7784292
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_282 - /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

react-native-track-player:3.1.0
device: simulator
running OS: iOS

@kyimoemin kyimoemin added the Bug label Sep 8, 2022
@puckey
Copy link
Collaborator

puckey commented Sep 8, 2022

@kyimoemin please provide an example audio file which gives this issue

@mpivchev mpivchev changed the title duration value is always '0' in useProgress hooks [iOS] Duration value is always '0' in useProgress hooks Sep 8, 2022
puckey added a commit to puckey/react-native-track-player that referenced this issue Sep 13, 2022
- (breaking) fix: usePlaybackState was incorrectly returning State.None by default. Now it returns undefined while it is waiting on the async call to TrackPlayer to resolve. This also fixes the following issue where duration was incorrectly being reported as `0`: doublesymmetry#1709
- optimization: avoid unnecessarily reevaluating the useEffect on every player state change by moving the `playerState === State.None` outside of the effect and including it as a dependency instead
@puckey
Copy link
Collaborator

puckey commented Sep 13, 2022

See #1723 for a fix candidate

@jspizziri
Copy link
Collaborator

@kyimoemin @chrismadalina,

As puckey referenced please try the nightly build as this might be fixed there. Apart from that we need your feedback based on our recommendation it might be a bad audio file.

Please try send a reproduction based on the example app from a fork of this lib.

If we hear back with something that merits further inquiry I'll open this issue again.

puckey added a commit to puckey/react-native-track-player that referenced this issue Sep 14, 2022
- (breaking) fix: usePlaybackState was incorrectly returning State.None by default. Now it returns undefined while it is waiting on the async call to TrackPlayer to resolve. This also fixes the following issue where duration was incorrectly being reported as `0`: doublesymmetry#1709
- optimization: avoid unnecessarily reevaluating the useEffect on every player state change by moving the `playerState === State.None` outside of the effect and including it as a dependency instead
jspizziri pushed a commit that referenced this issue Sep 14, 2022
* fix(js): fix useProgress & usePlayback hooks

- (breaking) fix: usePlaybackState was incorrectly returning State.None by default. Now it returns undefined while it is waiting on the async call to TrackPlayer to resolve. This also fixes the following issue where duration was incorrectly being reported as `0`: #1709
- optimization: avoid unnecessarily reevaluating the useEffect on every player state change by moving the `playerState === State.None` outside of the effect and including it as a dependency instead

* chore(js): make hooks fix non-breaking
@mmxdr
Copy link

mmxdr commented Sep 20, 2022

@jspizziri @puckey hey, i have the same issue on 3.1.0 and either on the nightly build

here is an example audio

this is how i add tracks:

const addTracks = useCallback(async (tracks: Track[], index: number) => {
    await TrackPlayer.reset();
    await TrackPlayer.add(tracks);
    await TrackPlayer.skip(index);
    await TrackPlayer.play();
  }, []);

@jspizziri
Copy link
Collaborator

@drachyovmaxim please fork of this repository and create a reproduction in the example project. We will reopen this if we can confirm it there.

@mmxdr
Copy link

mmxdr commented Sep 21, 2022

@jspizziri we fixed this issue on backend side by adding Content-Range header.

hlieb53 added a commit to hlieb53/react-native-track-player that referenced this issue Nov 9, 2023
* fix(js): fix useProgress & usePlayback hooks

- (breaking) fix: usePlaybackState was incorrectly returning State.None by default. Now it returns undefined while it is waiting on the async call to TrackPlayer to resolve. This also fixes the following issue where duration was incorrectly being reported as `0`: doublesymmetry/react-native-track-player#1709
- optimization: avoid unnecessarily reevaluating the useEffect on every player state change by moving the `playerState === State.None` outside of the effect and including it as a dependency instead

* chore(js): make hooks fix non-breaking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants