[bug] Android after a minute in the background, local audio and video streams stoping (freezes)
Android after a minute in the background, local audio and video streams stoping (freezes), I keep hearing the incoming stream When moving to the foreground, audio and video are restored
No issues found!
Plugin version: v2.1.4 Flutter target OS: Android Flutter target OS version: Android API 33+ log: AudioFlinger_Threads audioserver I create audiotrack
@afl-dev do you have a solution for this?
@afl-dev do you have a solution for this? workaround, run background service, see ios/.symlinks/plugins/flutter_webrtc/example/lib/src/get_display_media_sample.dart
Future<void> selectScreenSourceDialog
Hey guys,
I had the exact problem on screen sharing in Android, and solved it by adding these service types and these permissions to the Foreground Service on AndroidManifest:
Permissions:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
Service:
<service
android:name="de.julianassmann.flutter_background.IsolateHolderService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="mediaProjection|microphone|camera" />
A side note, the microphone and camera only work in the background after having launched the foreground service, which on the demo app is only done when screen sharing. After that, even while not screen sharing, mic and camera keep working in the background, because the service was started. So what I'm doing is starting the background service as soon as the call starts.
Hope it helps!
@EvertonMJunior Thanks for this.
Just to clarify, when you say ...launched the foreground service... do you mean calling this method from the demo:
Future<void> requestBackgroundPermission([bool isRetry = false]) async {
if (Platform.isAndroid) {
try {
var isPermitted = await FlutterBackground.hasPermissions;
if (!isRetry) {
const androidConfig = FlutterBackgroundAndroidConfig(
notificationTitle: 'Live Broadcast',
notificationText: 'A broadast/stream is live now',
);
isPermitted = await FlutterBackground.initialize(androidConfig: androidConfig);
}
if (isPermitted && !FlutterBackground.isBackgroundExecutionEnabled) {
await FlutterBackground.enableBackgroundExecution();
}
} catch (e) {
if (!isRetry) {
return Future.delayed(Duration(seconds: 1), () => requestBackgroundPermission(true));
}
Logger().e('Could not start background process');
}
}
}
Because when I do this, I get a TimeOutException after calling this method.