Just_audio: Exception on playing my audio

Created on 24 Aug 2020  路  12Comments  路  Source: ryanheise/just_audio


Which API doesn't behave as documented, and how does it misbehave?
setAsset, setURL, setFilePath all of them throws the same exception when playing some audio file recorded using _flutterRecorder_,

  • Extension is .wav
  • sampling rate is 16000
  • file is playing normally using other players in my phone
  • file is playing normally using AudioPlayers plugin
    Minimal reproduction project
    https://github.com/hesham91fci/just_audio

To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:

  1. Embed the located (.wav) file as an asset in your pubspec.yaml
  2. try to play it using setAsset method
  3. use method play() to play the file
  4. see the following error message in error message section

Error messages

E/ExoPlayerImplInternal(12865): Source error
E/ExoPlayerImplInternal(12865):   com.google.android.exoplayer2.ParserException: Expected block size: 2; got: 1
E/ExoPlayerImplInternal(12865):       at com.google.android.exoplayer2.extractor.wav.WavExtractor$PassthroughOutputWriter.<init>(WavExtractor.java:222)
E/ExoPlayerImplInternal(12865):       at com.google.android.exoplayer2.extractor.wav.WavExtractor.read(WavExtractor.java:122)
E/ExoPlayerImplInternal(12865):       at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:982)
E/ExoPlayerImplInternal(12865):       at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391)
E/ExoPlayerImplInternal(12865):       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
E/ExoPlayerImplInternal(12865):       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
E/ExoPlayerImplInternal(12865):       at java.lang.Thread.run(Thread.java:764)
E/AudioPlayer(12865): TYPE_SOURCE: Expected block size: 2; got: 1
E/flutter (12865): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: (0) com.google.android.exoplayer2.ParserException: Expected block size: 2; got: 1
E/flutter (12865): #0      AudioPlayer._load (package:just_audio/just_audio.dart:461:9)
E/flutter (12865): <asynchronous suspension>
E/flutter (12865): #1      AudioPlayer.load (package:just_audio/just_audio.dart:425:30)
E/flutter (12865): #2      AudioPlayer.setAsset (package:just_audio/just_audio.dart:411:7)
E/flutter (12865): #3      _MyHomePageState._listenToAudio (package:just_audio_example/main.dart:52:23)
E/flutter (12865): #4      _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:45:6)
E/flutter (12865): #5      _MyHomePageState._listenToAudio (package:just_audio_example/main.dart:50:30)
E/flutter (12865): #6      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
E/flutter (12865): #7      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
E/flutter (12865): #8      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (12865): #9      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter (12865): #10     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter (12865): #11     BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:199:7)
E/flutter (12865): #12     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:467:9)
E/flutter (12865): #13     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter (12865): #14     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:117:9)
E/flutter (12865): #15     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter (12865): #16     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:115:18)
E/flutter (12865): #17     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:7)
E/flutter (12865): #18     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter (12865): #19     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (12865): #20     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (12865): #21     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (12865): #22     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (12865): #23     _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter (12865): #24     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (12865): #25     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter (12865): #26     _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter (12865): #27     _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)

Expected behavior
Audio file should plays normally.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: MacOS catalina
  • Browser [Chrome]

Smartphone (please complete the following information):

  • Device: [Sony xperia XA1 ultra]
  • OS: [Android 8.0]

Flutter SDK version

[鉁揮 Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.4 19E287,
    locale en-EG)

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses
[鉁揮 Xcode - develop for iOS and macOS (Xcode 11.4.1)
[鉁揮 Android Studio (version 3.5)
[鉁揮 Connected device (1 available)

Additional context
I've modified the original pubspec file as I'm using flutter 1.12.13.

1 backlog bug

Most helpful comment

@ryanheise I switched the recorder plugin from flutter_audio_recorder to audio_recorder and it worked fine

All 12 comments

Hi @hesham91fci , unfortunately parsing errors are outside of my control since the issue is with ExoPlayer itself (Google's media player library). You can post a bug report on Google's issues page and provide a link to the wav file that is triggering the issue:

https://github.com/google/ExoPlayer/issues

@ryanheise Thanks a lot for your immediate reply, but can you please demonstrate why AudioPlayer plugin plays this file normally ?

Do you mean the audioplayer plugin? That is because it is using an older Android API that doesn't have this bug. The latest APIs, however, have this bug.

@ryanheise , yes I mean AudioPlayer plugin, Does it means that falling back to versions earlier than 0.3.4 could be the fix ?

You'd have to go back to 0.0.1. Not really a good option since the latest APIs are the most powerful.

One thing you can try as a workaround is use a different audio recorder plugin. I haven't checked them all, but if you can find one that records and encodes in a different format, you might be able to dodge the parsing error when it comes time to play it.

Looking at what's available, a number of them support recording to AAC which will probably work better for you as in addition to possibly fixing your parsing error, it will also compress the audio.

Also another technical question, isn't just_audio plugin wraps inside it AudioPlayer plugin ?

just_audio was written independently from the ground up using the latest APIs. As such, it has no relation to any other audio plugin on pub.dev.

Same here. This report is just for record case.

I generated the Wave file from https://github.com/rmbrone/flutter_audio_recorder/.

In my case, the android mediaplayer seems to work well for the first time. Strange.

Anyway, thanks for your all great work! 馃憤 馃憤 馃憤 馃憤

@dfdgsdfg what if you encode to a different audio format?

@ryanheise In my case, the recorder generated a bad header.

https://github.com/rmbrone/flutter_audio_recorder/issues/11

I think, there is no problem with exoplayer or just_audio.

Thanks.

@dfdgsdfg I agree, thanks for investigating it. I'll close this issue, and recommend those who run into this issue to wait for a fix in the recorder plugin or switch to another recorder plugin that outputs the correct header.

@ryanheise I switched the recorder plugin from flutter_audio_recorder to audio_recorder and it worked fine

Was this page helpful?
0 / 5 - 0 ratings

Related issues

creativecreatorormaybenot picture creativecreatorormaybenot  路  7Comments

Alphabets007 picture Alphabets007  路  8Comments

lain-ke picture lain-ke  路  4Comments

ryanheise picture ryanheise  路  13Comments

snaeji picture snaeji  路  10Comments