anarchuser / mic_stream

Flutter plugin to get an infinite audio stream from the microphone
https://pub.dev/packages/mic_stream
GNU General Public License v3.0
100 stars 68 forks source link

Reset previous audio session category on onCancel #67

Closed CarmeloBeeapp closed 8 months ago

CarmeloBeeapp commented 1 year ago

Into startCapture method, there is an override of audioSession category but the previous category wasn't set after stopping the session

anarchuser commented 1 year ago

Hey, thank you for your work. I kindly ask you to open an issue wherein you describe the problem you are trying to solve here. Since I'm not an iOS developer I need a bit more information to understand the necessity of this change

CarmeloBeeapp commented 1 year ago

Hi, There is an open issue for this problem: https://github.com/anarchuser/mic_stream/issues/66

The PR doesn't change anything on your functionalities, it only resets the previous AudioSession category when the registration is completed

anarchuser commented 1 year ago

If I understand your changes correctly, you store the current session category when starting to record, and write it back once recording ends. This seems like a reasonable change to me. I don't see how it solves issue #66, though, since there the problem seems to be the new category we write, not the one active before we start recording.

CarmeloBeeapp commented 1 year ago

Sorry, you're right. The issue #66 it's a little different, they try to record and play at the same time, instead I want to play audio before and after recording. The audio before the recording works correctly but without the change, the audio after the recording doesn't work

anarchuser commented 1 year ago

sorry for the wait. The goal of your PR is to save the current category on listen and restore it on cancel, right?

GuillaumeBouxin commented 1 year ago

I've tried this MR, and it's working well but when the sound is resumed it is much less loud. Any idea?

anarchuser commented 1 year ago

One possibility could be that resuming mixes up parts of the audio settings and thus continues recording with a different category.

Otherwise, how are you playing back the audio? If it's on the phone also, do you notice any changes in the playback volume slider?

Also, if you print samples before and after resume, do they differ?

GuillaumeBouxin commented 1 year ago

I'm playing back the audio with the "JustAudio" plugin and the volume slider is unchanged

CarmeloBeeapp commented 1 year ago

I updated the MR, "onCancel" in SwiftMicStreamPlugin.swift was not called. I added a channel method ("clean") to reset the audio session manually

brightsign-ed commented 1 year ago

@CarmeloBeeapp I've been having a go with the latest version to see if it resolves the volume issue (we also experience this in the same way). Unfortunately, I'm not able to get it to build or run due to the use of the oldAudioSessionCategoryOptions variable which never seems to be initialised anywhere?

Does this commit build and run for you and if so, where is that variable coming from?

CarmeloBeeapp commented 1 year ago

@brightsign-ed Sorry, I forgot to push some changes. Now you shouldn't have build failures

brightsign-ed commented 1 year ago

I'll have a play again today and see how it goes 👍

I wonder if it is worth implementing a noAutomaticSession option to prevent any of these mechanisms from running if the user doesn't want them to. I know other packages like flutter_sound basically leave you to manage your own audio session if you want to as it can make things more interoperable between different audio packages.

The only downside is that you have to be careful as the user to make sure you are configuring the session for what the underlying packages all need.

GuillaumeBouxin commented 8 months ago

This is working well for me, any plan to merge on master and create a new version?

anarchuser commented 8 months ago

ah, sorry, I've been very busy. I try to get it done ASAP.

anarchuser commented 8 months ago

Due to this PR being out-of-date I put the changes on a separate branch (fix/67/reset_audio_category) and published it as 0.7.2-dev. Please give feedback about whether it works as intended or if any issues arise.