flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
9.82k stars 384 forks source link

Device Wakelock #2999

Open syleishere opened 2 months ago

syleishere commented 2 months ago

People using audioplayers package cannot get a wakelock on android to continue playing music, soon as screen turns off or app is backgrounded.

The flutter package https://pub.dev/packages/wakelock_plus seems to solve this issue, the video player would need it as well. Modifications would be needed to AndroidManifest.xml to add the permission.

I believe it would need a partial wakelock for audio, and full wakelock for video.

ndonkoHenri commented 2 months ago

I think Video already has wakelock: https://flet.dev/docs/controls/video#wakelock

syleishere commented 2 months ago

I believe the reason it may not be working in video is because AndroidManifest.xml does not include permission for it when I tried before. I haven't been able to test video on android lately because of a recent gradle upgrade on android studio that is breaking the --include-packages flet_video:

PS C:\Users\dan\flet\crystaltunes>  flet build apk  --include-packages flet_video
Creating Flutter bootstrap project...OK
Customizing app icons and splash images...OK
Generating app icons...OK
Generating splash screens...OK
Packaging Python app...OK
Building .apk for Android...Resolving dependencies...
  file_picker 6.2.1 (8.0.0+1 available)
  fl_chart 0.65.0 (0.67.0 available)
  flutter_lints 2.0.3 (3.0.2 available)
  flutter_native_splash 2.3.7 (2.4.0 available)
  js 0.6.7 (0.7.1 available)
  leak_tracker 10.0.0 (10.0.5 available)
  leak_tracker_flutter_testing 2.0.1 (3.0.5 available)
  leak_tracker_testing 2.0.1 (3.0.1 available)
  lints 2.1.1 (3.0.0 available)
  material_color_utilities 0.8.0 (0.11.1 available)
  meta 1.11.0 (1.14.0 available)
  package_info_plus 4.2.0 (7.0.0 available)
  package_info_plus_platform_interface 2.0.1 (3.0.0 available)
  petitparser 5.4.0 (6.0.2 available)
  screen_brightness 0.2.2+1 (1.0.0 available)
  screen_brightness_android 0.1.0+2 (1.0.0 available)
  screen_brightness_ios 0.1.0 (1.0.0+1 available)
  screen_brightness_macos 0.1.0+1 (1.0.0 available)
  screen_brightness_platform_interface 0.1.0 (1.0.0 available)
  screen_brightness_windows 0.1.3 (1.0.0 available)
  sensors_plus 4.0.2 (5.0.1 available)
  test_api 0.6.1 (0.7.1 available)
  toml 0.14.0 (0.15.0 available)
  vm_service 13.0.0 (14.2.0 available)
  wakelock_plus 1.2.1 (1.2.3 available)
  xml 6.3.0 (6.5.0 available)
Got dependencies!
26 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.

Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'...                           26.0s

┌─ Flutter Fix ──────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin.                     │
│ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then │
│ update C:\Users\dan\AppData\Local\Temp\flet_flutter_build_kwigAlZUdy\android\build.gradle: │
│ ext.kotlin_version = '<latest-version>'                                                    │
└────────────────────────────────────────────────────────────────────────────────────────────┘

e: Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
e: C:/Users/dan/.gradle/caches/transforms-3/6498ee1438a7a83cb4725beb055db98c/transformed/jetified-kotlin-stdlib-1.9.23.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with
an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C:/Users/dan/.gradle/caches/transforms-3/6498ee1438a7a83cb4725beb055db98c/transformed/jetified-kotlin-stdlib-1.9.23.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with
an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C:/Users/dan/.gradle/caches/transforms-3/6498ee1438a7a83cb4725beb055db98c/transformed/jetified-kotlin-stdlib-1.9.23.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an
incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
e: C:\Users\dan\AppData\Local\Pub\Cache\hosted\pub.dev\wakelock_plus-1.2.1\android\src\main\kotlin\dev\fluttercommunity\plus\wakelock\Messages.g.kt: (14, 10): Unresolved reference: listOf
e: C:\Users\dan\AppData\Local\Pub\Cache\hosted\pub.dev\wakelock_plus-1.2.1\android\src\main\kotlin\dev\fluttercommunity\plus\wakelock\Messages.g.kt: (19, 12): Unresolved reference: listOf
e: C:\Users\dan\AppData\Local\Pub\Cache\hosted\pub.dev\wakelock_plus-1.2.1\android\src\main\kotlin\dev\fluttercommunity\plus\wakelock\Messages.g.kt: (25, 12): Unresolved reference: listOf
e: C:\Users\dan\AppData\Local\Pub\Cache\hosted\pub.dev\wakelock_plus-1.2.1\android\src\main\kotlin\dev\fluttercommunity\plus\wakelock\Messages.g.kt: (26, 17): Unresolved reference: javaClass
e: C:\Users\dan\AppData\Local\Pub\Cache\hosted\pub.dev\wakelock_plus-1.2.1\android\src\main\kotlin\dev\fluttercommunity\plus\wakelock\Messages.g.kt: (55, 6): Class 'kotlin.Suppress' was
compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
The class is loaded from C:/Users/dan/.gradle/caches/transforms-3/6498ee1438a7a83cb4725beb055db98c/transformed/jetified-kotlin-stdlib-1.9.23.jar!/kotlin/Suppress.class

Yeah I have to agree at this point in time, the video plugin would be a much better idea to build a music player with as it supports playlists, without playlist support, normal audio plugin will not be able to play more than one song on web when someone switches tabs in the browser.

If you can fix the video player compile issues, I should be able to test if wakelock works or not when you add permission to AndroidManifest.xml for it. Last time I was able to test video, android would kill it off within a few minutes when I shut screen off, and that was with wakelock set to True.

syleishere commented 2 months ago

I still stand by my original post though, even if we can get video player working correctly in android. This plugin should be a separate plugin. In the future of flet people may develop apps that need screen on, say for map navigation in their car, background audio, cooking recipes whatever. A generic plugin for android that can act as a foreground service for everyone where they could put custom icons/controls/images on users display as well will be what is needed and what I think will make flet really stand out for developers.

I think we might need a customized plugin that makes it easy for people to run a foreground service on android, maybe a function where they could add custom controls/icons/background images to users screen. I think that would make flet really stand out as a developers paradise and gain it huge popularity with developers, as any serious developers are going to target android and iphone before anything else.

In latest news from google, anyone running a foreground service on android targeting later API versions, will now have to make a youtube video of their app before submitting to playstore. Also anyone targetting later API version will now not be able to get a wakelock either without a foreground service.

So as not to make developers lives complete hell, a plugin that can start a foreground service, issue wakelocks if needed etc will just make flet hugely popular. As it stands now, unless a developer was able to pull in custom foreground service plugins from flutter themselves, flet would be completely useless to them. Which would be really sad as python is most popular language on the planet, especially with AI.

syleishere commented 2 months ago

hey guys, is there any way you can wrap mediakit with https://pub.dev/packages/audio_service I would be most grateful, https://crystaltunes.sunsaturn.com:9000/music
this is project currently working on, I really need to finish project before June 26th and I cannot without that plugin otherwise it will be useless on android/iphone etc. Would need AndroidManifest.xml edits and plist for Iphone as well according to that page.

I have tested wakelock on flet_video and works fine, but ultimately audio_service plugin is what I really need personally.