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

Keep microphone alive in background when other audio app open #47

Open
yelkamel opened this issue Oct 18, 2022 · 5 comments
Open

Keep microphone alive in background when other audio app open #47

yelkamel opened this issue Oct 18, 2022 · 5 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@yelkamel
Copy link

yelkamel commented Oct 18, 2022

Hello,

I really like this package and his simplicity.

In my app, I wanna to be able to keep listenning in background even if another app like Youtube is open.

I see that some app who use microphone (like SleepCycle) is keeping the microphone alive in background even if the user open Youtube app.

So it's shoud be possible to do that in Flutter.

Regards,

@anarchuser
Copy link
Owner

anarchuser commented Oct 18, 2022

This plugin does not interfere in the life cycle management of apps. As long as the mobile operating system does not suspend an app recording audio, the app should keep on recording.

Note that the example application does pause recording because it has been designed to do so, by explicitly managing the life cycle of apps: example/lib/main.dart#L261-L285

Also note that other apps may potentially interfere with the recording process; this is outside of control for this plugin.

@anarchuser
Copy link
Owner

I recommend you to try it out by cloning this repository, removing every line from function

void didChangeAppLifecycleState(AppLifecycleState state) {}

and then check if the app keeps on recording or not by looking at the log.

If you do encounter issues, please reopen this issue with concrete information about what happened.

@anarchuser anarchuser added invalid This doesn't seem right could not reproduce Unable to reproduce and fix error it labels Oct 18, 2022
@yelkamel
Copy link
Author

yelkamel commented Oct 25, 2022

Hello @anarchuser

Thanks for you answer.
I did what you say, and still the same thing, Youtube app terminate the microphone listenner.

According to the doc:
https://developer.apple.com/library/archive/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/HandlingAudioInterruptions/HandlingAudioInterruptions.html

I think it's because I have an interruption because:
"Interruptions happen when a competing audio session from an app is activated and that session is not categorized by the system to mix with yours."

So I want to level up the audio session priority.
But when I change the AudioSource with
audioSource: AudioSource.VOICE_CALL,

I have a crash:

mic_stream/SwiftMicStreamPlugin.swift:76: Fatal error: Unexpectedly found nil while unwrapping an Optional value
* thread #1, queue = 'com.apple.main-thread', stop reason = Fatal error: Unexpectedly found nil while unwrapping an Optional value
    frame #0: 0x0000000189be83d4 libswiftCore.dylib`_swift_runtime_on_report

I think it's because we don't have this value in the enum even if there is in dart side.
enum AudioSource : Int { case DEFAULT } in SwiftMicStreamPlugin.swift

Edit:
I just saw that in the native code

                    events(FlutterError(code: "-3",
                                        message: "Currently only default AUDIO_SOURCE (id: 0) is supported", details:nil))
                    return nil
                }```
When this will change ? :) 

Regards,

@anarchuser
Copy link
Owner

Thank you for your detailed report.
The problem, however, is that I cannot reliably fix this issue. I only wrote the android part of the plugin; the iOS and macOS parts I integrated from pull requests.

@anarchuser anarchuser reopened this Oct 25, 2022
@anarchuser anarchuser added bug Something isn't working wontfix This will not be worked on and removed invalid This doesn't seem right could not reproduce Unable to reproduce and fix error it labels Oct 25, 2022
@anarchuser
Copy link
Owner

I will have a look at the issue but it is unlikely that I am able to fix this.

If you want, please have a look at the issue and try to fix it yourself. I am happy to provide my support and, if you do manage to fix it, integrate it into the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants