just_audio icon indicating copy to clipboard operation
just_audio copied to clipboard

Some audio file produce errors. Might be an encoding issue.

Open JKazma opened this issue 2 years ago • 6 comments

Which API doesn't behave as documented, and how does it misbehave? audioPlayer.setUrl() is not working. Some audio files are not being processed correctly which results in the error below.

Minimal reproduction project Provide a link here using one of two options: The example

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

  • Try to load this audio file and it should work: https://drive.google.com/uc?export=download&id=1IIgx7EiFu2IA4B3fd-yR2eHvW9YZjBaT
  • Try to load this audio file and it should fail: https://drive.google.com/uc?export=download&id=1OFrRjyxujGAiFR9BUyBwYLtV88oz27ch

Error messages

Error: (4) Failed to load URL
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49  throw_
packages/just_audio/just_audio.dart 850:9                                                                                  _load
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 60:31            <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1658:54                                          runBinary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 162:22                                    handleError
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 778:46                                    handleError
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 799:13                                    _propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 574:5                                     [_completeError]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 665:7                                     callback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15           <fn>

Expected behavior The audio player to start playing the file properly or a way to catch that error so that I can notify the user that the audio file is not compatible.

Platform Web using Chrome

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.10, on Microsoft Windows [Version 10.0.19042.685], locale en-CA)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    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
[!] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.20)
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK
[√] Android Studio (version 2021.3)
[√] IntelliJ IDEA Community Edition (version 2020.3)
[√] VS Code (version 1.68.0)
[√] Connected device (3 available)
[√] HTTP Host Availability

! Doctor found issues in 2 categories.

Additional context Add any other context about the problem here.

JKazma avatar Jan 12 '23 10:01 JKazma

Isn't there supposed to be a section in the bug report for which platform this is? There are pertinent differences between iOS and Android here.

Without knowing the platform, I notice that your URLs are served without proper response headers. You should at least have a correct content-type, but additionally it is helpful to use correct headers for range requests.

ryanheise avatar Jan 12 '23 12:01 ryanheise

My mistake, I added the platform to the post, its on flutter Web using the chrome browser. I'm not sure how I can add response headers to a file uploaded to google drive.

JKazma avatar Jan 12 '23 21:01 JKazma

I'm not sure how to change headers on Google Drive either, I can only tell you about just_audio. To rule that out, you could try hosting the file on another web server that does headers correctly.

ryanheise avatar Jan 13 '23 01:01 ryanheise

I've also tried using the following API:

audioPlayer.setAudioSource(BufferAudioSource(widget.bytes!));

Where the bytes are obtained using:

FilePickerResult? result = await picker.pickFiles(type: fileType);
result.files.first.bytes;

And the BufferAudioSource is defined as:

class BufferAudioSource extends StreamAudioSource {
  final Uint8List _buffer;

  BufferAudioSource(this._buffer) : super();

  @override
  Future<StreamAudioResponse> request([int? start, int? end]) {
    start = start ?? 0;
    end = end ?? _buffer.length;

    return Future.value(
      StreamAudioResponse(
        sourceLength: _buffer.length,
        contentLength: end - start,
        offset: start,
        contentType: 'audio/mpeg',
        stream:
        Stream.value(List<int>.from(_buffer.skip(start).take(end - start))),
      ),
    );
  }
}

And I tried many different contentTypes to no avail.

I ran the following ffprobe commands and I can see some differences but I don't really know what they imply. I'm still trying to figure it out but I'll add the output just in case someone else might have a better understanding.

 ffprobe -i Minute\ Waltz-working.m4a
ffprobe version 4.3.1-2021-01-01-full_build-www.gyan.dev Copyright (c) 2007-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev5, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Minute Waltz-working.m4a':
  Metadata:
    major_brand     : M4A
    minor_version   : 512
    compatible_brands: M4A isomiso2
    title           : Waltz No. 6 in D flat major, Op. 64/1, "Minute"
    artist          : Chopin
    album_artist    : Chopin
    album           : The Very Best Of Chopin
    date            : 2005
    encoder         : Lavf59.27.100
    comment         : dussin
    genre           : Classical
    track           : 5/24
  Duration: 00:01:49.55, start: 0.000000, bitrate: 129 kb/s
    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
ffprobe -i Minute\ Waltz-not\ working.m4a
ffprobe version 4.3.1-2021-01-01-full_build-www.gyan.dev Copyright (c) 2007-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev5, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 00000135ffbe18c0] stream 0, timescale not set
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Minute Waltz-not working.m4a':
  Metadata:
    major_brand     : M4A
    minor_version   : 512
    compatible_brands: M4A mp42isom
    creation_time   : 2012-03-31T02:07:14.000000Z
    track           : 5/24
    genre           : Classical
    album           : The Very Best Of Chopin
    album_artist    : Chopin
    artist          : Chopin
    comment         : dussin
    title           : Waltz No. 6 in D flat major, Op. 64/1, "Minute"
    encoder         : CUETools.2.05
    date            : 2005
  Duration: 00:01:49.55, start: 0.000000, bitrate: 430 kb/s
    Stream #0:0(und): Audio: alac (alac / 0x63616C61), 44100 Hz, stereo, s16p, 425 kb/s (default)
    Metadata:
      creation_time   : 2012-03-31T02:07:14.000000Z
    Stream #0:1: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 500x500 [SAR 96:96 DAR 1:1], 90k tbr, 90k tbn, 90k tbc (attached pic)

JKazma avatar Jan 13 '23 03:01 JKazma

There have been some reports that the content type sometimes doesn't work on stream audio sources so the rule that out I recommend testing on a proper server.

ryanheise avatar Jan 13 '23 05:01 ryanheise

@JKazma Try hosting your audio files on Firebase storage and use their respective links to stream the audio. Note that, suppose you re-upload a given audio file, the link for that audio file will change on Firebase Storage. So, you will have to update the link in your app as well.

flutternoob avatar Jan 26 '23 11:01 flutternoob

This will help https://www.youtube.com/watch?v=IMQdSTlTXjA

BraveEvidence avatar Mar 15 '23 11:03 BraveEvidence