Open ipainchaud opened 9 months ago
I attempted to create a PR which would create the "mediaProjection" foreground service just after a successful call to mediaProjectionManager.createScreenCaptureIntent()
to solve this problem. I based myself on the flutter_foreground_service plugin which does something fairly similar. To ensure my logic was sound, I first wrote the logic on my native project and ensured it was working, then copied it to a fork of flutter_webrtc. This was to no avail though. My lack of understanding of Android is most probably at fault here. It would seem that calling context.startForegroundService(myMediaProjectionServiceIntent)
, although returning the right ComponentName, would never execute either of my Service's onCreate
or onStartCommand
functions. I suspect there might be something related with the context used to create the foreground service (context rights or scope?).
I did try to understand this further by looking into adb logcat
and found this warning every time I attempted to start the foreground service: "ForegroundServiceTypeLoggerModule: API event end called before start!".
@ipainchaud
Describe the bug
It has been a while that we had to start a foreground service of type
mediaProjection
to be able to start a screen share usingMediaDevices.getDisplayMedia(constraints)
to avoid the following error:With SDK Version 34 (
targetSdkVersion 34
) though the requirements have changed around the creation ofmediaProjection
services. There is now a runtime requisite:Meeting this requisite doesn't seem possible using
getDisplayMedia
because of how it is implemented (see here where the Receiver starts the media capture straight after receiving the permission).If you attempt to create the service before calling
getDisplayMedia
on an app targeting SDK Version 34 on an android 14 phone, you will now get:Not only we now have to add the
FOREGROUND_SERVICE_MEDIA_PROJECTION
and one of theCAPTURE_VIDEO_OUTPUT
orandroid:project_media
permission to AndroidManifest.xml, but you also have to get the User's permission for the media projection before you start themediaProjection
foreground service and then start acquiring the media projection.To Reproduce
Android Only: Create a project targeting SDK Version 34 where you create a foreground service of type "mediaProjection" before calling
getDisplayMedia
.Expected behavior
We should be able to provide a callback function to
getDisplayMedia
to create the "mediaProjection" service at the right timeOR have the plugin taking care of creating that service.
Platform information
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) • Android SDK at /Users/israelpainchaud/Library/Android/sdk • Platform android-34, build-tools 33.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15C500b • CocoaPods version 1.14.3
[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2) • Android Studio at /Applications/Android Studio Chipmonk.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] Android Studio (version 2023.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
[✓] IntelliJ IDEA Community Edition (version 2022.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin version 222.4560
[✓] Connected device (4 available)
• SM G991U1 (mobile) • R3CNC0JE7KR • android-arm64 • Android 14 (API 34) • Israel’s iPhone (mobile) • 00008110-001E19E80E62401E • ios • iOS 17.4 21E5184k • macOS (desktop) • macos • darwin-x64 • macOS 14.1.2 23B92 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 121.0.6167.139
[✓] Network resources • All expected network resources are available.