ryanheise / just_audio

Audio Player
1.06k stars 681 forks source link

Quote issue 814, there is still a problem on the Android platform #868

Open zhushenwudi opened 2 years ago

zhushenwudi commented 2 years ago

Which API doesn't behave as documented, and how does it misbehave? https://github.com/ryanheise/just_audio/issues/814#issue-1373717611

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

  1. clone https://github.com/zhushenwudi/just_audio_demo
  2. click play button

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

  1. build android project and run at similator
  2. see error

Error messages

  1. when I click play button on arm64 api31 simulator will be ANR

    E/ActivityManager: ANR in com.zhushenwudi.just_audio_demo
    PID: 23188
    Reason: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{9e47f3a u0 com.zhushenwudi.just_audio_demo/com.ryanheise.audioservice.AudioService}
    ErrorId: c373ee85-8a1a-4586-b4f0-612d3d62b24f
    Frozen: false
    Load: 0.58 / 0.32 / 0.2
    ----- Output from /proc/pressure/memory -----
    some avg10=0.00 avg60=0.00 avg300=0.00 total=36635820
    full avg10=0.00 avg60=0.00 avg300=0.00 total=16313809
    ----- End output from /proc/pressure/memory -----
    
    CPU usage from 51996ms to 0ms ago (2022-11-08 11:33:45.593 to 2022-11-08 11:34:37.589):
      3.8% 528/system_server: 2.2% user + 1.6% kernel / faults: 19734 minor 93 major
      0.4% 1091/com.google.android.apps.nexuslauncher: 0.1% user + 0.2% kernel / faults: 4417 minor 44 major
      1.6% 340/android.hardware.graphics.composer@2.3-service: 0.1% user + 1.5% kernel / faults: 8 minor
      1.2% 364/surfaceflinger: 0.3% user + 0.8% kernel / faults: 541 minor 7 major
      1.1% 805/com.android.systemui: 0.2% user + 0.9% kernel / faults: 2399 minor 62 major
      0.8% 328/android.hardware.audio.service: 0.2% user + 0.6% kernel / faults: 22 minor
      0.7% 361/audioserver: 0.3% user + 0.3% kernel / faults: 85 minor 17 major
      0.3% 351/android.hardware.sensors@2.1-service.multihal: 0.1% user + 0.2% kernel
      0.3% 409/adbd: 0.1% user + 0.2% kernel / faults: 2149 minor
      0.2% 175/logd: 0% user + 0.1% kernel / faults: 28 minor
      0.2% 997/com.android.networkstack.process: 0% user + 0.1% kernel / faults: 335 minor 3 major
      0.1% 316/dhcpclient: 0% user + 0.1% kernel
      0.1% 487/llkd: 0% user + 0.1% kernel
      0.1% 12/ksoftirqd/0: 0% user + 0.1% kernel
      0.1% 18972/com.google.android.googlequicksearchbox:search: 0.1% user + 0% kernel / faults: 3910 minor 21 major
      0% 22646/kworker/0:2-events: 0% user + 0% kernel
      0.1% 23110/kworker/0:1-events: 0% user + 0.1% kernel
      0.1% 322/netd: 0% user + 0.1% kernel / faults: 181 minor
      0.1% 435/logcat: 0% user + 0.1% kernel
      0.1% 470/media.swcodec: 0% user + 0% kernel / faults: 546 minor 9 major
      0% 13/rcu_preempt: 0% user + 0% kernel
      0% 1038/com.android.phone: 0% user + 0% kernel / faults: 452 minor 12 major
      0% 321/statsd: 0% user + 0% kernel / faults: 38 minor
      0% 17804/com.google.android.gms: 0% user + 0% kernel / faults: 1875 minor
      0% 22242/logcat: 0% user + 0% kernel
      0% 354/android.hardware.wifi@1.0-service: 0% user + 0% kernel
      0% 1347/com.google.android.inputmethod.latin: 0% user + 0% kernel / faults: 366 minor 1 major
      0% 5815/com.google.android.gms.persistent: 0% user + 0% kernel / faults: 217 minor 9 major
      0% 22716/kworker/u8:0-events_unbound: 0% user + 0% kernel
      0% 22998/kworker/u8:3-events_unbound: 0% user + 0% kernel
      0% 798/com.android.bluetooth: 0% user + 0% kernel / faults: 149 minor
      0% 1/init: 0% user + 0% kernel / faults: 220 minor 6 major
      0% 41/khugepaged: 0% user + 0% kernel
      0% 109/kswapd0: 0% user + 0% kernel
      0% 123/sugov:0: 0% user + 0% kernel
      0% 124/sugov:1: 0% user + 0% kernel
      0% 126/sugov:3: 0% user + 0% kernel
      0% 138/kworker/2:1H-kblockd: 0% user + 0% kernel
      0% 180/qemu-props: 0% user + 0% kernel / faults: 1 minor 1 major
      0% 192/android.system.suspend@1.0-service: 0% user + 0% kernel / faults: 3 minor
      0% 323/zygote64: 0% user + 0% kernel / faults: 42 minor 1 major
      0% 339/android.hardware.graphics.allocator@3.0-service: 0% user + 0% kernel / faults: 7 minor
      0% 342/android.hardware.media.c2@1.0-service-goldfish: 0% user + 0% kernel / faults: 175 minor 14 major
      0% 447/media.metrics: 0% user + 0% kernel / faults: 140 minor
      0% 448/mediaserver: 0% user + 0% kernel / faults: 104 minor
      0% 18928/kworker/3:1-mm_percpu_wq: 0% user + 0% kernel
      0% 19531/kworker/2:1-mm_percpu_wq: 0% user + 0% kernel
      0% 21373/com.android.chrome: 0% user + 0% kernel / faults: 1 minor 4 major
      0% 22360/kworker/u9:2-blk_crypto_wq: 0% user + 0% kernel
      0% 28702/kworker/1:2-mm_percpu_wq: 0% user + 0% kernel
     +0% 23188/com.zhushenwudi.just_audio_demo: 0% user + 0% kernel
    E/ActivityManager: 4.5% TOTAL: 1.9% user + 2.2% kernel + 0% iowait + 0.2% irq + 0.1% softirq
    CPU usage from 7ms to 231ms later (2022-11-08 11:34:37.597 to 2022-11-08 11:34:37.820):
      9.3% 528/system_server: 0% user + 9.3% kernel / faults: 268 minor
        13% 23263/AnrConsumer: 4.6% user + 9.3% kernel
      4.8% 23188/com.zhushenwudi.just_audio_demo: 4.8% user + 0% kernel
    4.4% TOTAL: 2.2% user + 1.1% kernel + 1.1% irq
    I/just_audio_dem(21992): Thread[6,tid=22018,WaitingInMainSignalCatcherLoop,Thread*=0xb400007b6f111f50,peer=0x136001f8,"Signal Catcher"]: reacting to signal 3
  2. crashing when playing
    D/BufferPoolAccessor2.0(22959): bufferpool2 0xb400007adf15cf68 : 4(131072 size) total buffers - 1(32768 size) used buffers - 231/240 (recycle/alloc) - 10/476 (fetch/transfer)
    D/BufferPoolAccessor2.0(22959): bufferpool2 0xb400007adf15cf68 : 4(131072 size) total buffers - 1(32768 size) used buffers - 287/296 (recycle/alloc) - 10/588 (fetch/transfer)
    D/BufferPoolAccessor2.0(22959): bufferpool2 0xb400007adf15cf68 : 4(131072 size) total buffers - 1(32768 size) used buffers - 343/352 (recycle/alloc) - 10/700 (fetch/transfer)
    D/BufferPoolAccessor2.0(22959): bufferpool2 0xb400007adf15cf68 : 4(131072 size) total buffers - 1(32768 size) used buffers - 399/408 (recycle/alloc) - 10/812 (fetch/transfer)
    D/BufferPoolAccessor2.0(22959): bufferpool2 0xb400007adf15cf68 : 4(131072 size) total buffers - 1(32768 size) used buffers - 455/464 (recycle/alloc) - 10/924 (fetch/transfer)
    D/BufferPoolAccessor2.0(22959): bufferpool2 0xb400007adf15cf68 : 4(131072 size) total buffers - 1(32768 size) used buffers - 511/520 (recycle/alloc) - 10/1036 (fetch/transfer)
    D/BufferPoolAccessor2.0(22959): bufferpool2 0xb400007adf15cf68 : 4(131072 size) total buffers - 1(32768 size) used buffers - 567/576 (recycle/alloc) - 10/1148 (fetch/transfer)
    D/CCodecBufferChannel(22959): [c2.android.flac.decoder#667] work failed to complete: 14
    E/MediaCodec(22959): Codec reported err 0xe, actionCode 0, while in state 6/STARTED
    D/CCodecBufferChannel(22959): [c2.android.flac.decoder#667] work failed to complete: 22
    E/MediaCodec(22959): Codec reported err 0x16, actionCode 0, while in state 0/UNINITIALIZED
    E/MediaCodecAudioRenderer(22959): Audio codec error
    E/MediaCodecAudioRenderer(22959):   android.media.MediaCodec$CodecException: Error 0xe
    E/ExoPlayerImplInternal(22959): Playback error
    E/ExoPlayerImplInternal(22959):   com.google.android.exoplayer2.ExoPlaybackException: MediaCodecAudioRenderer error, index=1, format=Format(null, null, null, audio/flac, null, -1, null, [-1, -1, -1.0], [2, 44100]), format_supported=YES
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:566)
    E/ExoPlayerImplInternal(22959):       at android.os.Handler.dispatchMessage(Handler.java:102)
    E/ExoPlayerImplInternal(22959):       at android.os.Looper.loopOnce(Looper.java:201)
    E/ExoPlayerImplInternal(22959):       at android.os.Looper.loop(Looper.java:288)
    E/ExoPlayerImplInternal(22959):       at android.os.HandlerThread.run(HandlerThread.java:67)
    E/ExoPlayerImplInternal(22959):   Caused by: com.google.android.exoplayer2.mediacodec.MediaCodecDecoderException: Decoder failed: c2.android.flac.decoder
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.createDecoderException(MediaCodecRenderer.java:945)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:813)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:989)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:490)
    E/ExoPlayerImplInternal(22959):       ... 4 more
    E/ExoPlayerImplInternal(22959):   Caused by: android.media.MediaCodec$CodecException: Error 0xe
    E/ExoPlayerImplInternal(22959): Disable failed.
    E/ExoPlayerImplInternal(22959):   java.lang.IllegalStateException
    E/ExoPlayerImplInternal(22959):       at android.media.MediaCodec.native_flush(Native Method)
    E/ExoPlayerImplInternal(22959):       at android.media.MediaCodec.flush(MediaCodec.java:2350)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.mediacodec.AsynchronousMediaCodecAdapter.flush(AsynchronousMediaCodecAdapter.java:228)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.flushCodec(MediaCodecRenderer.java:877)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.flushOrReleaseCodec(MediaCodecRenderer.java:870)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.onDisabled(MediaCodecRenderer.java:710)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.onDisabled(MediaCodecAudioRenderer.java:603)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.BaseRenderer.disable(BaseRenderer.java:186)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.ExoPlayerImplInternal.disableRenderer(ExoPlayerImplInternal.java:1651)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.ExoPlayerImplInternal.resetInternal(ExoPlayerImplInternal.java:1392)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.ExoPlayerImplInternal.stopInternal(ExoPlayerImplInternal.java:1355)
    E/ExoPlayerImplInternal(22959):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:582)
    E/ExoPlayerImplInternal(22959):       at android.os.Handler.dispatchMessage(Handler.java:102)
    E/ExoPlayerImplInternal(22959):       at android.os.Looper.loopOnce(Looper.java:201)
    E/ExoPlayerImplInternal(22959):       at android.os.Looper.loop(Looper.java:288)
    E/ExoPlayerImplInternal(22959):       at android.os.HandlerThread.run(HandlerThread.java:67)
    D/CCodecBufferChannel(22959): [c2.android.flac.decoder#667] MediaCodec discarded an unknown buffer
    D/CCodecBufferChannel(22959): [c2.android.flac.decoder#667] MediaCodec discarded an unknown buffer
    I/hw-BpHwBinder(22959): onLastStrongRef automatically unlinking death recipients
    E/AudioPlayer(22959): TYPE_RENDERER: Decoder failed: c2.android.flac.decoder
    E/flutter (22959): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(1, MediaCodecAudioRenderer error, index=1, format=Format(null, null, null, audio/flac, null, -1, null, [-1, -1, -1.0], [2, 44100]), format_supported=YES, null, null)
    E/flutter (22959): 
    E/flutter (22959): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(1, MediaCodecAudioRenderer error, index=1, format=Format(null, null, null, audio/flac, null, -1, null, [-1, -1, -1.0], [2, 44100]), format_supported=YES, null, null)
    E/flutter (22959): 
    E/flutter (22959): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(1, MediaCodecAudioRenderer error, index=1, format=Format(null, null, null, audio/flac, null, -1, null, [-1, -1, -1.0], [2, 44100]), format_supported=YES, null, null)
    E/flutter (22959): 
    E/flutter (22959): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(1, MediaCodecAudioRenderer error, index=1, format=Format(null, null, null, audio/flac, null, -1, null, [-1, -1, -1.0], [2, 44100]), format_supported=YES, null, null)
    E/flutter (22959): 
    D/BufferPoolAccessor2.0(22959): bufferpool2 0xb400007adf15cf68 : 0(0 size) total buffers - 0(0 size) used buffers - 613/623 (recycle/alloc) - 10/1232 (fetch/transfer)
    D/BufferPoolAccessor2.0(22959): evictor expired: 1, evicted: 1

Expected behavior Make the program no longer ANR and play the track without crashing

Screenshots iShot_2022-11-08_11 35 11

Desktop (please complete the following information):

Smartphone (please complete the following information):

Flutter SDK version

[✓] Flutter (Channel stable, 3.0.2, on macOS 12.6 21G115 darwin-arm, locale
    zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 14.0)
[✓] Chrome - develop for the web
[!] Android Studio
    ✗ Unable to find bundled Java version.
[✓] Android Studio (version 2021.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.1)
[✓] VS Code (version 1.68.1)
[✓] Connected device (3 available)
    ! Error: iPhone is not connected. Xcode will continue when iPhone is
      connected and unlocked. (code -13)
[✓] HTTP Host Availability

Additional context Add any other context about the problem here.

rogisolorzano commented 1 year ago

Recently ran into this same error and found that it was because I had missed the permissions that were needed in the Android Setup instructions.

Took a look at your example repo, looks like you're missing those permissions in your AndroidManifest.xml as well?

    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
ryanheise commented 1 year ago

The submitted minimal reproduction project indeed has no permissions declared in the manifest, so that could well be it. @zhushenwudi , does that resolve your issue?

zhushenwudi commented 1 year ago

ok, i will test later

zhushenwudi commented 1 year ago

I have tested it and currently it can be played without any unresponsive issues. Quote issue #991 , found that the current setAudioSource method must be passed into the TAG attribute, otherwise an error will be reported. Please put the tag in the compulsory parameter, or check null on just_audio_background.dart 488 line before rotation type. it will be great