flutter_sound
flutter_sound copied to clipboard
[BUG] Muting OFF on Android
Flutter Sound Version :
-
Released version
-
Version number: ^7.4.14+1
-
FULL flavor
-
Result of the command "flutter pub deps | grep flutter_sound"
|-- flutter_sound 7.4.14+1
| |-- flutter_sound_platform_interface 7.4.14+1
| |-- flutter_sound_web 7.4.14+1
| | |-- flutter_sound_platform_interface...
Severity
- Result is not what expected
Platforms you faced the error
- Some Android real devices
Logs
When recording:
I/AudioManager(29542): In stopBluetoothSco(), calling application: com.landa.app
I/AudioManager(29542): In setBluetoothScoOn(), on: false, calling application: com.landa.app
I/AudioManager(29542): In setSpeakerphoneOn(), on: true, calling application: com.landa.app
I/AudioManager(29542): In setSpeakerphoneOn(), on: true, calling application: com.landa.app
I/AudioManager(29542): In setBluetoothScoOn(), on: false, calling application: com.landa.app
I/AudioManager(29542): In stopBluetoothSco(), calling application: com.landa.app
When playing the sound:
I/flutter (29542): FS:---> openAudioSession
I/AudioManager(29542): In stopBluetoothSco(), calling application: com.landa.app
I/AudioManager(29542): In setBluetoothScoOn(), on: false, calling application: com.landa.app
I/AudioManager(29542): In setSpeakerphoneOn(), on: true, calling application: com.landa.app
I/AudioManager(29542): In setSpeakerphoneOn(), on: true, calling application: com.landa.app
I/AudioManager(29542): In setBluetoothScoOn(), on: false, calling application: com.landa.app
I/AudioManager(29542): In stopBluetoothSco(), calling application: com.landa.app
I/flutter (29542): FS:---> channelMethodCallHandler : openAudioSessionCompleted
I/flutter (29542): FS:<--- channelMethodCallHandler : openAudioSessionCompleted
I/flutter (29542): FS:<--- openAudioSession
I/flutter (29542): FS:---> setSubscriptionDuration
I/flutter (29542): FS:<---- setSubscriptionDuration
I/flutter (29542): FS:---> startPlayer
I/flutter (29542): FS:---> stop
I/flutter (29542): FS:<--- stop
I/flutter (29542): FS:---> _convert
I/flutter (29542): FS:---> needToConvert
I/flutter (29542): FS:<--- needToConvert
I/flutter (29542): FS:<--- _convert
I/flutter (29542): FS:<--- startPlayer
D/FlautoPlayer(29542): mediaPlayer prepared and started
I/flutter (29542): FS:---> channelMethodCallHandler : startPlayerCompleted
I/flutter (29542): FS:<--- channelMethodCallHandler : startPlayerCompleted
I/flutter (29542): audioPlayerListener 0:00:00.000000 0:00:02.560000
I/flutter (29542): audioPlayerListener 0:00:00.345000 0:00:02.560000
I/flutter (29542): audioPlayerListener 0:00:00.846000 0:00:02.560000
I/flutter (29542): audioPlayerListener 0:00:01.348000 0:00:02.560000
I/flutter (29542): audioPlayerListener 0:00:01.849000 0:00:02.560000
I/flutter (29542): audioPlayerListener 0:00:02.349000 0:00:02.560000
D/FlautoPlayer(29542): Playback completed.
V/MediaPlayer(29542): resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(29542): cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer(29542): resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(29542): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter (29542): FS:---> channelMethodCallHandler : audioPlayerFinishedPlaying
I/flutter (29542): FS:---> audioPlayerFinished
I/flutter (29542): FS:---> stopPlayer
I/flutter (29542): FS:---> stop
I/flutter (29542): FS:---> closeAudioSession
I/flutter (29542): FS:---> stop
I/flutter (29542): FS:<--- audioPlayerFinished
I/flutter (29542): FS:<--- channelMethodCallHandler : audioPlayerFinishedPlaying
I/flutter (29542): FS:<--- stop
I/flutter (29542): FS:<--- stopPlayer
I/flutter (29542): FS:<--- stop
I/flutter (29542): FS:<--- closeAudioSession
Describe the bug Some Android devices record as expected but when playing this record file, no sound is heard. If I try to play this record file on other devices, there is no sound either.
Additional context**
This problem is faced in a BQ X2. Moto G9 works fine. No problem found in iOS.
Which codec ?
Do you use a bluetooth microphone ? A bluetooth Headset ?
Using the Codec.aacADTS
. The Bluetooth is off (but has the same behavior with Bluetooth on).
For what I see in your logs, it seems that a correct Audio File was recorded. It plays correctly with a callback every 300 ms.
If there is nos sound, it should be because of a blank record, and not a bad record. Is that true ?
Is the recorded length correct ?
It is correct. Those records have a correct length, so as you say a blank record.
OK. So the problem is not in the recorder nor the player. The problem is because for an unknown reason, the microphone is not correctly linked to the player.
Perhaps your Android device does not allow opening the microphone (But I think we would have an error when starting the player). If you are sure that the record is blank (playing it elsewhere), you should look (and play) with the 'device:' parameter of openAudioSession() or setAudiofocus().
I suggest that you leave the default values for all the parameters of openAudioSession(), both for the player and the recorder
And do not use setAudioFocus() during these first tests.
AudioSessions are flaw. You can read this. I will work soon on this subject.
I confirm it is a blank record because this device can play other records (from other devices).
Right now I'm not using the setAudioFocus
method. This is my code:
if (!recordingAudio) {
rRecorder = FlutterSoundRecorder();
audioPath = await createTempAudioFileName();
var outputFile = File(audioPath);
await rRecorder.openAudioSession();
await rRecorder.setSubscriptionDuration(Duration(milliseconds: 500));
recordProgress = rRecorder.onProgress.listen((event) {
recordDuration = event.duration;
refreshScreen();
});
await rRecorder.startRecorder(
toFile: audioPath,
codec: Codec.aacADTS,
);
refreshScreen();
}
The same configuration is defined for the player.
I will check the openAudioSession
params.
Thanks for your work 😃
I guess that the dbPeakLevel that you get during Recorder.onProgress.listen((event) {
is 0.
Right ?
You are right:
I/AudioManager(29542): In stopBluetoothSco(), calling application: com.landa.app
I/AudioManager(29542): In setBluetoothScoOn(), on: false, calling application: com.landa.app
I/AudioManager(29542): In setSpeakerphoneOn(), on: true, calling application: com.landa.app
I/AudioManager(29542): In setSpeakerphoneOn(), on: true, calling application: com.landa.app
I/AudioManager(29542): In setBluetoothScoOn(), on: false, calling application: com.landa.app
I/AudioManager(29542): In stopBluetoothSco(), calling application: com.landa.app
I/flutter (29542): peak level: 0.0
I/flutter (29542): peak level: 0.0
I/flutter (29542): peak level: 0.0
I/flutter (29542): peak level: 0.0
I/flutter (29542): peak level: 0.0
I/flutter (29542): peak level: 0.0
The problem is definitely in the opening of the microphone. But I do not see exactly what.
Did you try the Flutter Sound Demo or/and the SimpleRecorder example ?
I've just tested the simple recorder demo and shows the same behavior (BQ X2).
Everything works fine in Moto G9.
Efra, I will need your contribution. I am going to build a patched version of Flutter Sound, and you will tell me the result. Probably not this evening, but tomorrow (Spain).
Perfect, thanks again!
Btw : what is the version of your Android device ?
It is Android 10.
I suggest that you give your device to a museum 🤣 . Please look to the SDK requirements
I am sorry, I mix Android Version and SDK Version. Android 10 is very new . Sorry.
I am just confused because Google does not use any more name for Android versions but number.
Talk with you tomorrow. Have a nice evening, Efra.
Don't worry. 🤣
Moto G9 and BQ X2 uses the same Android version, API level 29
Good morning Efra. Could you download and test this Patched Version of Flutter Sound ? Tell me if this file is too heavy. I will upload a lighter zip file.
This version :
- Force SDK 29 instead of 30
- Remove some code that I do not trust in
openAudioSession
- Force Mute(off)
- Force audioDevice := microphone
Thank you for your contribution : this bug is bad, and I really want to fix it. (Several users already complained that the Recorder records nothing, but I did not have enough informations to work on that)
It is a heavy ZIP, give me some minutes to check it. If you are working in a new branch I can checkout it to test the new changes.
The ZIP stills downloading (poor connection) but meanwhile I rebooted the device. Now everything works perfectly 😮
Do you mean that the records are not blanked anymore ?
That's right. I'm gonna check it on more android devices. I'm doing more tests to see if the problem appears again.
💯 : This is really great news. 👍
Now, I have just to determine which change is necessary in τ (Target SDK, OpenAudioSession() code, Mute off, or setting the audio device.
I will need more help from you for that. Now I am going to lunch. I will be back in 1 hour.
Maybe you can try to change back the "compileSdkVersion" from 29 to 30 in the files :
- tau_core/android/build.gradle
- flutter_sound/android/build.gradle
- flutter_sound/example/android/app/build.gradle (2 occurences)