just_audio icon indicating copy to clipboard operation
just_audio copied to clipboard

Play from file resets duration (Web)

Open NielsH12 opened this issue 4 years ago • 8 comments

Which API doesn't behave as documented, and how does it misbehave? AudioPlayer.play() sometimes resets the position on the AudioSource. Even AudioPlayer.seek() doesn't work. It is a bit inconsistent in it's behavior, and it's a bit outside my area of expertise. But as far as I can tell. It depends on whether the HTTP response from the server is 200 or 206. I have found it to fail more consistenly on larger files.

Minimal reproduction project https://github.com/NielsH12/just_audio

You might also be able to reproduce it with the existing sample file if you change main.dart to use the included mp3 file: await _player.setAudioSource(AudioSource.uri(Uri.file("audio/nature.mp3")));

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

  1. Run in browser (I've tested in Chrome and Edge)
  2. Click play and wait for a few seconds
  3. Click pause
  4. Click play again.
  5. File plays from beginning instead of resuming

Expected behavior I expected the playback to resume from where I paused.

Desktop (please complete the following information):

  • OS: Windows 10 Version 10.0.19043 Build 19043
  • Browser: Chrome Version 96.0.4664.110

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.5.2, on Microsoft Windows [Version 10.0.19043.1415], locale da-DK)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Android Studio (version 2020.3)
[√] IntelliJ IDEA Community Edition (version 2017.3)
[√] IntelliJ IDEA Ultimate Edition (version 2018.3)
[√] VS Code (version 1.63.2)
[√] Connected device (2 available)

! Doctor found issues in 1 category.

NielsH12 avatar Dec 19 '21 14:12 NielsH12

I'm a bit confused by your bug report since you talk about HTTP status codes and yet your example uses the file:// scheme.

ryanheise avatar Dec 19 '21 14:12 ryanheise

Like I saId, it's outside my area of expertise. But if I look at the developer tools in Chrome under networking, I see a Status 200. image

NielsH12 avatar Dec 19 '21 15:12 NielsH12

file:// URIs are not supported on web due to the security model.

ryanheise avatar Dec 20 '21 02:12 ryanheise

What does this mean? AudioPlayer can't play mp3 files on Flutter Web? Did you try the example I provided?

NielsH12 avatar Jan 03 '22 14:01 NielsH12

Is your intention to deploy this web app "on the web"? I'm trying to understand what use case you might have where you would need to use a file:// URI -- something that websites "on the web" would block.

ryanheise avatar Jan 03 '22 15:01 ryanheise

I'd like to host a webapp where clients can play their own mp3 files. As such, the files are only present client side. Am I going about this all wrong?

NielsH12 avatar Jan 03 '22 17:01 NielsH12

I can't provide advice on that, but you might try searching past questions on StackOverflow (not necessarily flutter-specific) or asking a new question, and once you have the advice on what features will help you build your app, you can then make a feature request here regarding what you need.

People have tried to do similar things in the past with just_audio so if you search the past issues on this page you might also find approaches that may currently work for some use cases.

ryanheise avatar Jan 04 '22 01:01 ryanheise

Perhaps the author is trying to load an mp3 file via input upload so what they get in return is a temp file:// path or a blob

netgfx avatar Aug 30 '22 08:08 netgfx

@netgfx Yup, that is exactly what I was trying to do.

NielsH12 avatar Sep 30 '22 08:09 NielsH12

Well you could try saving it locally https://stackoverflow.com/questions/67508623/how-to-save-streamedresponse-of-audio-to-file-in-flutter and then reading it from this library or use audio players https://stackoverflow.com/questions/65607152/how-can-i-play-local-mp3-on-flutter-web where you can provide the path of the file (although not sure it will play correctly)

Just to know that web can't do that either, its a browser security issue not a flutter one @NielsH12

netgfx avatar Sep 30 '22 08:09 netgfx

As I have said above, I don't believe you can use file:// URIs due to the web security model, but people have done this sort of thing so I recommend searching past issues. As for whether this is a bug, I don't think it's a bug since your code is trying to do something that is not supported by the web security model.

or use audio players https://stackoverflow.com/questions/65607152/how-can-i-play-local-mp3-on-flutter-web where you can provide the path of the file (although not sure it will play correctly)

No it won't play correctly because as mentioned, you can't use file:// URIs on the web due to the security model.

I will close this as it is not a bug.

However, I recommend searching past issues. What you need to do is use a file picker that doesn't give you the file path (which you can't use) but instead gives you a stream of bytes or an array of bytes. Once you have that, you can render that with your own StreamAudioSource. Searching past issues or StackOverflow questions about this may be helpful.

ryanheise avatar Sep 30 '22 08:09 ryanheise

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.

github-actions[bot] avatar Oct 15 '22 00:10 github-actions[bot]