Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix android audio issue when screen is off and broadcast audio session id #1247

Merged
merged 3 commits into from
Feb 25, 2024

Conversation

olivier2
Copy link
Contributor

I tested these changes on a couple of Android devices and everything was working. I'm pretty confident that favoring audiotrack output over opensles is safe. Adding the extra comma at the end ("audiotrack,opensles,"), makes libmpv select another audio output not provided in the list, but available on the device.

My flutter skills being low, I might not have properly named the variables, formatted the code or defined constants in the proper place, so constructive comments are welcomed 🙃

For reference, here's the list of devices I tested:

  • Pixel 6a
  • Pixel 2
  • Galaxy A01
  • Galaxy S7
  • Galaxy Tab S7
  • Fire HD 8 (10th gen)

…s off. Not familiar with libmpv, but seems to favor audiotrack audio output over opensles. KRTirtho#571
@KRTirtho
Copy link
Owner

KRTirtho commented Feb 24, 2024

Wow, that's a really awesome fix for this issue. I was trying to fix it for a quite a while. Thanks for the help ❤️

My flutter skills being low, I might not have properly named the variables, formatted the code or defined constants in the proper place, so constructive comments are welcomed 🙃

It is good enough for anyone who started writing dart recently. No worries. I'll clean it up a little bit after merging although most of it is correct and works 😄

@KRTirtho
Copy link
Owner

flutter_broadcasts is causing trouble in AndroidPluginRegistrant. Is it working for you?

Resolving dependencies...
  _fe_analyzer_shared 61.0.0 (67.0.0 available)
  analyzer 5.13.0 (6.4.1 available)
  app_package_maker 0.0.9 (0.3.6 available)
  app_package_maker_aab 0.0.9 (0.2.3 available)
  app_package_maker_apk 0.0.9 (0.2.3 available)
  app_package_maker_deb 0.0.9 (0.2.3 available)
  app_package_maker_dmg 0.0.9 (0.2.3 available)
  app_package_maker_exe 0.0.9 (0.2.3 available)
  app_package_maker_ipa 0.0.9 (0.2.3 available)
  app_package_maker_zip 0.0.9 (0.2.3 available)
  archive 3.4.5 (3.4.10 available)
  audio_service_mpris 0.1.0 (0.1.3 available)
  audio_session 0.1.16 (0.1.18 available)
  build_daemon 4.0.0 (4.0.1 available)
  build_resolvers 2.3.2 (2.4.2 available)
  build_runner 2.4.6 (2.4.8 available)
  build_runner_core 7.2.10 (7.3.0 available)
  built_value 8.6.2 (8.9.1 available)
  buttons_tabbar 1.3.7+1 (1.3.8 available)
  cached_network_image 3.3.0 (3.3.1 available)
  cached_network_image_platform_interface 3.0.0 (4.0.0 available)
  cached_network_image_web 1.1.0 (1.1.1 available)
  catcher_2 1.0.0 (1.2.3 available)
  change_case 1.1.0 (2.0.1 available)
  cli_util 0.4.0 (0.4.1 available)
  code_builder 4.6.0 (4.10.0 available)
  cross_file 0.3.3+5 (0.3.4+1 available)
  dart_style 2.3.2 (2.3.4 available)
  dbus 0.7.8 (0.7.10 available)
  device_info_plus 9.0.3 (9.1.2 available)
  dio 5.3.3 (5.4.1 available)
  disable_battery_optimization 1.1.0+1 (1.1.1 available)
  dots_indicator 2.1.2 (3.0.0 available)
  envied 0.3.0+3 (0.5.3 available)
  envied_generator 0.3.0+3 (0.5.3 available)
  ffi 2.1.0 (2.1.2 available)
  file_selector 1.0.1 (1.0.3 available)
  file_selector_android 0.5.0+3 (0.5.0+7 available)
  file_selector_ios 0.5.1+6 (0.5.1+8 available)
  file_selector_macos 0.9.3+2 (0.9.3+3 available)
  file_selector_platform_interface 2.6.1 (2.6.2 available)
  file_selector_web 0.9.2+1 (0.9.4+1 available)
  fluentui_system_icons 1.1.214 (1.1.229 available)
  flutter_app_builder 0.0.9 (0.3.7 available)
  flutter_app_packager 0.0.9 (0.3.7 available)
* flutter_broadcasts 0.4.0 (was 0.4.1 from git https:/imdatsolak/flutter_broadcasts.git at d58dd9)
  flutter_distributor 0.0.2 (0.3.7 available)
  flutter_gen_core 5.3.1 (5.4.0 available)
  flutter_gen_runner 5.3.1 (5.4.0 available)
  flutter_hooks 0.20.1 (0.20.5 available)
  flutter_inappwebview 5.7.2+3 (6.0.0 available)
  flutter_keyboard_visibility 5.4.1 (6.0.0 available)
  flutter_lints 2.0.3 (3.0.1 available)
  flutter_mailer 2.1.1 (2.1.2 available)
  flutter_native_splash 2.3.3 (2.3.13 available)
  flutter_plugin_android_lifecycle 2.0.16 (2.0.17 available)
  flutter_riverpod 2.4.3 (2.4.10 available)
  flutter_rust_bridge 1.82.1 (1.82.6 available)
  flutter_sharing_intent 1.1.0 (1.1.1 available)
  flutter_svg 1.1.6 (2.0.10+1 available)
  fluttertoast 8.2.2 (8.2.4 available)
  freezed 2.4.6 (2.4.7 available)
  go_router 12.1.3 (13.2.0 available)
  hooks_riverpod 2.4.3 (2.4.10 available)
! http 1.1.0 (overridden) (1.2.1 available)
  image 4.1.3 (4.1.7 available)
  image_picker 1.0.4 (1.0.7 available)
  image_picker_android 0.8.8 (0.8.9+3 available)
  image_picker_for_web 3.0.1 (3.0.2 available)
  image_picker_ios 0.8.8+2 (0.8.9+1 available)
  image_picker_platform_interface 2.9.1 (2.9.4 available)
  intl 0.18.1 (0.19.0 available)
  introduction_screen 3.1.11 (3.1.12 available)
  js 0.6.7 (0.7.1 available)
  leak_tracker 10.0.0 (10.0.4 available)
  leak_tracker_flutter_testing 2.0.1 (3.0.3 available)
  leak_tracker_testing 2.0.1 (3.0.1 available)
  lints 2.1.1 (3.0.0 available)
  logger 2.0.2 (2.0.2+1 available)
  mailer 6.0.1 (6.1.0 available)
  media_kit 1.1.7 (1.1.10+1 available)
  media_kit_libs_android_audio 1.3.5 (1.3.6 available)
  media_kit_libs_audio 1.0.3 (1.0.4 available)
  meta 1.11.0 (1.12.0 available)
  mime 1.0.4 (1.0.5 available)
  mutex 3.0.1 (3.1.0 available)
  package_info_plus 4.1.0 (5.0.1 available)
  path_provider 2.1.1 (2.1.2 available)
  path_provider_android 2.2.0 (2.2.2 available)
  path_provider_foundation 2.3.1 (2.3.2 available)
  path_provider_platform_interface 2.1.1 (2.1.2 available)
  permission_handler 11.0.1 (11.3.0 available)
  permission_handler_android 11.0.5 (12.0.5 available)
  permission_handler_apple 9.1.4 (9.4.0 available)
  permission_handler_platform_interface 3.11.5 (4.2.0 available)
  permission_handler_windows 0.1.3 (0.2.1 available)
  petitparser 5.4.0 (6.0.2 available)
  plugin_platform_interface 2.1.6 (2.1.8 available)
  pointycastle 3.7.3 (3.7.4 available)
  popover 0.2.8+2 (0.3.0 available)
  provider 6.0.5 (6.1.1 available)
  puppeteer 3.2.0 (3.7.0 available)
  riverpod 2.4.3 (2.5.0 available)
  sentry 7.9.0 (7.16.1 available)
  shared_preferences_foundation 2.3.4 (2.3.5 available)
  shared_preferences_platform_interface 2.3.1 (2.3.2 available)
  shared_preferences_web 2.2.1 (2.3.0 available)
  simple_icons 7.10.0 (10.1.3 available)
  skeletonizer 0.8.0 (1.0.1 available)
  smtc_windows 0.1.1 (0.1.2 available)
  source_gen 1.4.0 (1.5.0 available)
  spotify 0.12.0 (0.13.1 available)
  sqflite 2.3.0 (2.3.2 available)
  sqflite_common 2.5.0 (2.5.3 available)
  state_notifier 0.7.2+1 (1.0.0 available)
  synchronized 3.1.0 (3.1.0+1 available)
! system_tray 2.0.2 (overridden) (2.0.3 available)
  test_api 0.6.1 (0.7.0 available)
  time 2.1.3 (2.1.4 available)
  url_launcher 6.1.14 (6.2.5 available)
  url_launcher_android 6.1.0 (6.3.0 available)
  url_launcher_ios 6.1.5 (6.2.4 available)
  url_launcher_linux 3.0.6 (3.1.1 available)
  url_launcher_macos 3.0.7 (3.1.0 available)
  url_launcher_platform_interface 2.1.5 (2.3.2 available)
  url_launcher_web 2.0.20 (2.3.0 available)
  url_launcher_windows 3.0.8 (3.1.1 available)
  uuid 3.0.7 (4.3.3 available)
  vm_service 13.0.0 (14.0.0 available)
  web_socket_channel 2.4.0 (2.4.4 available)
  win32 5.0.7 (5.2.0 available)
  window_manager 0.3.6 (0.3.8 available)
  xdg_directories 1.0.3 (1.0.4 available)
  xml 6.3.0 (6.5.0 available)
  youtube_explode_dart 2.0.2 (2.1.0 available)
Changed 1 dependency!
134 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.
Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
Building with Flutter multidex support enabled.
You are applying Flutter's app_plugin_loader Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply

You are applying Flutter's main Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/go/flutter-gradle-plugin-apply

/Users/krtirtho/dev/spotube/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java:54: error: package de.kevlatus.flutter_broadcasts does not exist
      flutterEngine.getPlugins().add(new de.kevlatus.flutter_broadcasts.FlutterBroadcastsPlugin());
                                                                       ^
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDevDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 38s
Error: Gradle task assembleDevDebug failed with exit code 1


Exited (1).

@olivier2
Copy link
Contributor Author

No problem when cloning a fresh copy of my branch with flutter 3.16.9 and dart 3.2.6

I'll try with your dev branch

@olivier2
Copy link
Contributor Author

No problem building from your dev with my changes. I ran into issues because I was mixing flutter versions (fvm vs global installed outside fvm), but fvm has proxy for flutter and dart commands so I tried everything a 2nd time cleanly from the start in order to write the following steps and it worked. Here's what I did (on Windows) for reference:

git clone --branch dev https:/KRTirtho/spotube.git spotube-dev
cd spotube-dev
copy ..\spotube\.env .
git remote add olivier2 https:/olivier2/spotube.git
git pull olivier2 android-audio-session-broadcast-clean

...
Merge made by the 'ort' strategy.
lib/services/audio_player/mk_state_player.dart | 46 ++++++++++++++++++++++++--
pubspec.yaml | 1 +
2 files changed, 45 insertions(+), 2 deletions(-)

fvm list

┌─────────┬─────────┬─────────────────┬──────────────┬──────────────┬────────┐
│ Version │ Channel │ Flutter Version │ Dart Version │ Release Date │ Global │
├─────────┼─────────┼─────────────────┼──────────────┼──────────────┼────────┤
│ 3.19.1 │ stable │ 3.19.1 │ 3.3.0 │ Feb 21, 2024 │ │
└─────────┴─────────┴─────────────────┴──────────────┴──────────────┴────────┘

fvm flutter pub get
fvm dart run build_runner build --delete-conflicting-outputs --enable-experiment=records,patterns
fvm flutter build apk --debug

@KRTirtho
Copy link
Owner

KRTirtho commented Feb 25, 2024

I checked it now. And as you suspected, I was using a pre version of flutter through fvm.
It's builds and runs now after switching to 3.19.1

Silly mistake by me. Sorry for the trouble 😅

@KRTirtho
Copy link
Owner

I can't test it in any device right now, and I can't reproduce it. So I'm merging it sort of blindly😅, though the app builds, and no side effects are found
Thus, this PR is heavily dependent on community feedback. I'll update add it to nightly, so users can check it out, and they'll give feedbacks in the linked issue

@KRTirtho KRTirtho merged commit 17105a6 into KRTirtho:dev Feb 25, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compatibility with Wavelet (Android Headphone DSP app) Intermittent Distorted Audio
2 participants