ryanheise / just_audio

Audio Player
1.05k stars 675 forks source link

Using Lock Exoplayer Response Code 500 / Proxy Status Error: 400 #832

Closed matecode closed 2 years ago

matecode commented 2 years ago

Thanks for your great libraries ๐Ÿงก . I found an issue with the experimental LockCachingAudioSource in combination with background audio and headers. I tried my best to fulfil the Bug Report requirements :)

Which API doesn't behave as documented, and how does it misbehave? LockCachingAudioSource does not work in combination with headers set, at least if you use Just_audio_background (didnt try without background use) If you don't set headers everything works fine.

Minimal reproduction project https://github.com/matecode/just_audio/tree/LockCachingAudioSource-Header-Issue

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

  1. Clone repo
  2. Start playing -> Error from proxy (see below)
  3. Try plying without headers (has be null not an empty map)
  4. works as expected

Error messages

Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
Running Gradle task 'assembleDebug'...
Building with Flutter multidex support enabled.
โœ“  Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...
Debug service listening on ws://127.0.0.1:59027/zQKtBz6Lsss=/ws
Syncing files to device sdk gphone64 arm64...
I/ExoPlayerImpl( 7646): Init 58239c3 [ExoPlayerLib/2.17.1] [emulator64_arm64, sdk_gphone64_arm64, Google, 31]
W/t_audio_exampl( 7646): Accessing hidden method Landroid/media/AudioTrack;->getLatency()I (unsupported, reflection, allowed)
I/flutter ( 7646): Proxy request failed: Exception: HTTP Status Error: 400
I/flutter ( 7646): #0      LockCachingAudioSource._fetch (package:just_audio/just_audio.dart:2794:7)
I/flutter ( 7646): <asynchronous suspension>
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: HTTP Status Error: 400
E/flutter ( 7646): #0      LockCachingAudioSource._fetch (package:just_audio/just_audio.dart:2794:7)
E/flutter ( 7646): <asynchronous suspension>
E/flutter ( 7646): 
D/EGL_emulation( 7646): app_time_stats: avg=15.17ms min=2.92ms max=94.08ms count=55
I/flutter ( 7646): Proxy request failed: Exception: HTTP Status Error: 400
I/flutter ( 7646): #0      LockCachingAudioSource._fetch (package:just_audio/just_audio.dart:2794:7)
I/flutter ( 7646): <asynchronous suspension>
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: HTTP Status Error: 400
E/flutter ( 7646): #0      LockCachingAudioSource._fetch (package:just_audio/just_audio.dart:2794:7)
E/flutter ( 7646): <asynchronous suspension>
E/flutter ( 7646): 
D/EGL_emulation( 7646): app_time_stats: avg=4.48ms min=2.26ms max=5.97ms count=59
I/flutter ( 7646): Proxy request failed: Exception: HTTP Status Error: 400
I/flutter ( 7646): #0      LockCachingAudioSource._fetch (package:just_audio/just_audio.dart:2794:7)
I/flutter ( 7646): <asynchronous suspension>
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: HTTP Status Error: 400
E/flutter ( 7646): #0      LockCachingAudioSource._fetch (package:just_audio/just_audio.dart:2794:7)
E/flutter ( 7646): <asynchronous suspension>
E/flutter ( 7646): 
D/EGL_emulation( 7646): app_time_stats: avg=4.42ms min=2.54ms max=5.76ms count=60
D/EGL_emulation( 7646): app_time_stats: avg=4.00ms min=2.17ms max=6.65ms count=59
I/flutter ( 7646): Proxy request failed: Exception: HTTP Status Error: 400
I/flutter ( 7646): #0      LockCachingAudioSource._fetch (package:just_audio/just_audio.dart:2794:7)
I/flutter ( 7646): <asynchronous suspension>
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: HTTP Status Error: 400
E/flutter ( 7646): #0      LockCachingAudioSource._fetch (package:just_audio/just_audio.dart:2794:7)
E/flutter ( 7646): <asynchronous suspension>
E/flutter ( 7646): 
E/ExoPlayerImplInternal( 7646): Playback error
E/ExoPlayerImplInternal( 7646):   com.google.android.exoplayer2.ExoPlaybackException: Source error
E/ExoPlayerImplInternal( 7646):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:641)
E/ExoPlayerImplInternal( 7646):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:613)
E/ExoPlayerImplInternal( 7646):       at android.os.Handler.dispatchMessage(Handler.java:102)
E/ExoPlayerImplInternal( 7646):       at android.os.Looper.loopOnce(Looper.java:201)
E/ExoPlayerImplInternal( 7646):       at android.os.Looper.loop(Looper.java:288)
E/ExoPlayerImplInternal( 7646):       at android.os.HandlerThread.run(HandlerThread.java:67)
E/ExoPlayerImplInternal( 7646):   Caused by: com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 500
E/ExoPlayerImplInternal( 7646):       at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:396)
E/ExoPlayerImplInternal( 7646):       at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:258)
E/ExoPlayerImplInternal( 7646):       at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:84)
E/ExoPlayerImplInternal( 7646):       at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1009)
E/ExoPlayerImplInternal( 7646):       at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412)
E/ExoPlayerImplInternal( 7646):       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ExoPlayerImplInternal( 7646):       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ExoPlayerImplInternal( 7646):       at java.lang.Thread.run(Thread.java:920)
E/AudioPlayer( 7646): TYPE_SOURCE: Response code: 500
I/ExoPlayerImpl( 7646): Release 58239c3 [ExoPlayerLib/2.17.1] [emulator64_arm64, sdk_gphone64_arm64, Google, 31] [goog.exo.core, goog.exo.exoplayer, goog.exo.decoder, goog.exo.datasource]
I/flutter ( 7646): Error loading playlist: (0) Source error
I/flutter ( 7646): #0      AudioPlayer._load (package:just_audio/just_audio.dart:840:9)
I/flutter ( 7646): <asynchronous suspension>
I/flutter ( 7646): #1      AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1421:28)
I/flutter ( 7646): <asynchronous suspension>
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(0, Source error, null, null)
E/flutter ( 7646): 
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(0, Source error, null, null)
E/flutter ( 7646): 
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(0, Source error, null, null)
E/flutter ( 7646): 
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(0, Source error, null, null)
E/flutter ( 7646): 
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(abort, Connection aborted, null, null)
E/flutter ( 7646): 
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(abort, Connection aborted, null, null)
E/flutter ( 7646): 
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(abort, Connection aborted, null, null)
E/flutter ( 7646): 
E/flutter ( 7646): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(abort, Connection aborted, null, null)
E/flutter ( 7646): 
D/EGL_emulation( 7646): app_time_stats: avg=4.17ms min=2.24ms max=13.27ms count=58

Expected behavior The headers should be used for the request and there should be no error if using headers.

Smartphone (please complete the following information): Tested on

Flutter SDK version

[โœ“] Flutter (Channel stable, 3.3.4, on macOS 12.6 21G115 darwin-arm, locale de-DE)
[โœ“] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[โœ“] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[โœ“] Chrome - develop for the web
[โœ“] Android Studio (version 2021.2)
[โœ“] VS Code (version 1.71.2)
[โœ“] Connected device (4 available)
[โœ“] HTTP Host Availability

โ€ข No issues found!
ryanheise commented 2 years ago

Hi @matecode is this a duplicate of #594 ?

matecode commented 2 years ago

@ryanheise After reading through #594 im not 100% if it is duplicate because #594 is really hard to follow. I try my best to understand it, at the moment i think it could be another impact of the bug. I'm not 100% sure because on #594 it looks like the proxy is dying at some point, but for my error it seem to never work.

ryanheise commented 2 years ago

I have just tested regular just_audio without the background (since that's more minimal and helps narrow it down), and it also does reproduce the issue.

ryanheise commented 2 years ago

I've committed a fix to the fix/cache_headers branch if you'd like to test it.

matecode commented 2 years ago

Hallo @ryanheise ! I can confirm that headers are now working in the fix branch. Great work, thank you. ๐Ÿฆ„๐ŸŒˆ

ryanheise commented 2 years ago

Thanks for confirming that.

P.S. Nice edit on your comment ;-)

ryanheise commented 2 years ago

Note that I will need to do some further refactoring before I release this. I will let you know once that's done in case I break things again.

matecode commented 2 years ago

Sounds good! I use the fix branch in a MVP which is fine for me, would be nice if you can keep it running until you release the fix.

ryanheise commented 2 years ago

I've just done the refactoring. This may or may not break things. Would you like to test?

ryanheise commented 2 years ago

The refactored version has now been merged and published.

github-actions[bot] commented 2 years ago

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.