react-native-track-player icon indicating copy to clipboard operation
react-native-track-player copied to clipboard

duration value is showing buffered's value in useProgress hook

Open kyimoemin opened this issue 2 years ago • 1 comments

Describe the Bug

The duration value is showing a buffered value of useProgress hook [may be only in network audio]. For example, the actual audio file duration is 5 minutes but it only shows the buffered value. sometimes even position is showing a bigger value than both of duration and buffered value, like position is already at 3 seconds and playing audio smoothly but the duration and buffered value is at 2 seconds. it only happens a few seconds of the beginning of the audio.

Code To Reproduce

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

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

Environment Info: System: OS: macOS 11.4 CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz Memory: 156.66 MB / 8.00 GB Shell: 5.8 - /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.2 - /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: 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: 12.5.1/12E507 - /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 version ^2.1.3 Simulator MacOs

kyimoemin avatar Apr 19 '22 16:04 kyimoemin

Having the same issue on Android from commit 9b7d663

Any fix?

newfylox avatar Jun 01 '22 20:06 newfylox

Same here on iOS Simulator.

luco avatar Aug 13 '22 00:08 luco

Looking through source code related to this, I see the following which might be causing this bug:

https://github.com/doublesymmetry/SwiftAudioEx/blob/main/SwiftAudioEx/Classes/Observer/AVPlayerItemObserver.swift#L92-L95

        case AVPlayerItemKeyPath.duration:
            if let duration = change?[.newKey] as? CMTime {
                delegate?.item(didUpdateDuration: duration.seconds)
            }
        
        case AVPlayerItemKeyPath.loadedTimeRanges:
            if let ranges = change?[.newKey] as? [NSValue], let duration = ranges.first?.timeRangeValue.duration {
                delegate?.item(didUpdateDuration: duration.seconds)
            }

While the first case seems to do the right thing, the second case seems to be updating the duration from the loadedTimeRanges, which looks to be the playable duration – which is a different thing and something which probably also depends on where you have seeked into the audio item.

loadedTimeRanges An array of time ranges indicating media data that is readily available. https://developer.apple.com/documentation/avfoundation/avplayeritem/1389953-loadedtimeranges

This code was introduced in this commit back in 2018: https://github.com/doublesymmetry/SwiftAudioEx/commit/9072259631b03397c942fc3f00fe20d5e87775ce

puckey avatar Sep 01 '22 19:09 puckey

I am unable to reproduce this bug in the example app – @kyimoemin do you have an example of an mp3 file where this is occurring?

puckey avatar Sep 01 '22 19:09 puckey

Or perhaps @luco, @newfylox?

puckey avatar Sep 01 '22 19:09 puckey

I actually think this issue is a dupe of https://github.com/doublesymmetry/react-native-track-player/issues/1521 and has been fixed.

puckey avatar Sep 01 '22 20:09 puckey

@luco @newfylox @kyimoemin , please confirm or deny @puckey 's suspicion that this has been fixed. If we don't hear anything back to the contrary we're going to call this fixed.

jspizziri avatar Sep 01 '22 21:09 jspizziri

Sorry for the late response, it works fine in the android simulator now, but the duration is always '0' in the iOS simulator.

kyimoemin avatar Sep 06 '22 16:09 kyimoemin

@kyimoemin what kind of track are you using? Is it a live stream?

jspizziri avatar Sep 06 '22 17:09 jspizziri

not live stream, normal mp3 audio file. it works in android so the bug may remain only in iOS

kyimoemin avatar Sep 06 '22 17:09 kyimoemin

@kyimoemin could you open a fresh issue for the duration of 0 for iOS?

Thanks!

jspizziri avatar Sep 06 '22 17:09 jspizziri

@jspizziri will do, thanks

kyimoemin avatar Sep 06 '22 17:09 kyimoemin

Sorry for late reply, I can't confirm because we stopped the project in which I was working in.

newfylox avatar Sep 06 '22 19:09 newfylox