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

durationStream reports wrong total duration on iOS with youtube audio streams #1386

Closed
garolard opened this issue Jan 5, 2025 · 2 comments
Closed
Assignees
Labels
1 backlog bug Something isn't working

Comments

@garolard
Copy link

garolard commented Jan 5, 2025

Which API doesn't behave as documented, and how does it misbehave?
durationStream reports a wrong total duration on iOS when getting audio streams from youtube using youtube_explode_dart library, usually it reports the double duration of the original source. In Android, instead, it reports the correct duration.
I'm getting the stream URL in the same way for both platforms, no custom streaming audio source, no clipping, no edition, just the bare audio uri fetched with youtube_explode.

Minimal reproduction project
https://github.com/garolard/just_audio_duration_ios

This example project should run as it is in both ios an android. When you push the start button and the stream finish to load, you can check the duration in iOS is practically the double reported on android.

This is the code to load the stream:

final yt = YoutubeExplode();
final video = await yt.videos.get(
        'https://www.youtube.com/watch?v=wOjzo02Tmck&pp=ygUcbGEgaW5jb25kaWNpb25hbCBsdWlzIG1pZ3VlbA%3D%3D');
final manifest = await yt.videos.streamsClient.getManifest(video.id);
await _player.setUrl(manifest.audioOnly.first.url.toString());
await _player.play();

To Reproduce (i.e. user steps, not code)

  1. Run the app
  2. Click on 'start' and wait for the audio to load
  3. The total duration in iOS is not the same as in Android.

Expected behavior
The total duration should be equal in both platforms

Screenshots

Captura de pantalla 2025-01-05 a las 11 53 58

Smartphone (please complete the following information):

  • Device: iPhone 15
  • OS: iOS 18.1.1

Flutter SDK version

[✓] Flutter (Channel stable, 3.27.1, on macOS 15.1.1 24B91 darwin-arm64, locale
    es-ES)
    • Flutter version 3.27.1 on channel stable at
      /opt/homebrew/Caskroom/flutter/3.13.9/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 17025dd882 (3 weeks ago), 2024-12-17 03:23:09 +0900
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/gabriel/Library/Android/sdk
    • Platform android-35, build-tools 33.0.1
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.11+0-17.0.11b1207.24-11852314)

[✓] VS Code (version 1.96.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (5 available)
    • Redmi Note 9 Pro (mobile)       • c39a967d                  •
      android-arm64  • Android 12 (API 31)
    • iPhone de Gabriel (mobile)      • 00008120-001604390151A01E • ios
      • iOS 18.1.1 22B91
    • macOS (desktop)                 • macos                     • darwin-arm64
      • macOS 15.1.1 24B91 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin
      • macOS 15.1.1 24B91 darwin-arm64
    • Chrome (web)                    • chrome                    •
      web-javascript • Google Chrome 131.0.6778.205

[✓] Network resources
    • All expected network resources are available.

@garolard garolard added 1 backlog bug Something isn't working labels Jan 5, 2025
@ryanheise
Copy link
Owner

I'm not sure on the legality of streaming YouTube content from outside of YouTube's official app (see Tyrrrz/YoutubeExplode#713) so I'm not particularly keen to investigate this mystery. What I can say is that the duration on iOS comes directly from the operating system itself since I leverage the underlying iOS platform to decode a given audio resource and extract its duration. The problem could be in iOS, or it could be in the data source itself (with the reason it's working on Android being that Android ignores the faulty duration metadata and determines the duration another way, such as by brute force or estimation). I'm not going to try to dig any deeper into this, but if it's happening consistently on iOS, you could just work around it in your app by dividing the reported duration by 2 if on iOS. Or if you wanted to dig deeper to get to the bottom of this, e.g. by examining the metadata or headers yourself, I'll leave that to you.

@garolard
Copy link
Author

garolard commented Jan 5, 2025

I understand ryan, I don't want to involve you in this particular regard. I'm gonna try to solve it someway by myself, thank you for your fast response.

@garolard garolard closed this as completed Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants