Open efraespada opened 3 years ago
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 :
openAudioSession
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 :
Yeah, and it seems a problem with the device system.
If the problem reappears, I'm gonna check the native recorder of the device (I forget to do it before the reboot).
Demo tested (with compileSdkVersion 30
and targetSdkVersion 30
) and working in all devices:
You have many devices !!!
In procedure setAudioDevices() of module FlautoSession.java (tau_core/android/src/... ) I added :
audioManager.setMicrophoneMute(false);
You can try if still OK without this instruction.
setAudioFocus() ( not setAudioDevices)
At the top of procedure startRecorder() I changed :
int audioSource = tabAudioSource[_audioSource.ordinal()];
//audioSource =MediaRecorder.AudioSource.MIC; // Just for test
by
int audioSource = MediaRecorder.AudioSource.MIC; // Just for test // PATCH LARPOUX
You can try reverse back to the previous instruction
(Module FlautoRecorder.java in tau_core)
And finally you can try to revert back the setAudioFocus() code in module FlautoSession :
public boolean setAudioFocus(t_AUDIO_FOCUS focus, t_SESSION_CATEGORY category, t_SESSION_MODE sessionMode, int audioFlags, t_AUDIO_DEVICE audioDevice)
{
boolean r = true;
audioManager = ( AudioManager ) Flauto.androidContext.getSystemService( Context.AUDIO_SERVICE );
if ( Build.VERSION.SDK_INT >= 26 )
{
if ( focus != t_AUDIO_FOCUS.abandonFocus && focus != t_AUDIO_FOCUS.doNotRequestFocus && focus != t_AUDIO_FOCUS.requestFocus )
{
int focusGain = AudioManager.AUDIOFOCUS_GAIN;
switch (focus)
{
case requestFocusAndDuckOthers: focusGain = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK; ; break;
case requestFocusAndKeepOthers: focusGain = AudioManager.AUDIOFOCUS_GAIN; ; break;
case requestFocusTransient: focusGain = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT; break;
case requestFocusTransientExclusive: focusGain = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE; break;
case requestFocusAndInterruptSpokenAudioAndMixWithOthers: focusGain = AudioManager.AUDIOFOCUS_GAIN; break;
case requestFocusAndStopOthers: focusGain = AudioManager.AUDIOFOCUS_GAIN; break;
}
audioFocusRequest = new AudioFocusRequest.Builder( focusGain )
// .setAudioAttributes(mPlaybackAttributes)
.build();
// change the audio input/output device
switch (audioDevice)
{
case speaker:
//if (isBluetoothHeadsetConnected())
//audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
//else
//audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.stopBluetoothSco();
audioManager.setBluetoothScoOn(false);
audioManager.setSpeakerphoneOn(true);
break;
case blueTooth:
case blueToothA2DP:
//audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
if (isBluetoothHeadsetConnected())
{
audioManager.startBluetoothSco();
audioManager.setBluetoothScoOn(true);
}
audioManager.setSpeakerphoneOn(false);
break;
case earPiece:
case headset:
//audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.stopBluetoothSco();
audioManager.setBluetoothScoOn(false);
audioManager.setSpeakerphoneOn(false);
}
}
if (focus != t_AUDIO_FOCUS.doNotRequestFocus)
{
if ( audioFocusRequest == null )
{
audioFocusRequest = new AudioFocusRequest.Builder ( AudioManager.AUDIOFOCUS_GAIN )
.build ();
}
hasFocus = (focus != t_AUDIO_FOCUS.abandonFocus);
if (hasFocus)
audioManager.requestAudioFocus ( audioFocusRequest );
else
audioManager.abandonAudioFocusRequest ( audioFocusRequest );
}
audioManager.setSpeakerphoneOn( (audioFlags & outputToSpeaker) != 0);
audioManager.setBluetoothScoOn( (audioFlags & allowBlueTooth) != 0);
if ((audioFlags & allowBlueTooth) != 0)
audioManager.startBluetoothSco();
else
audioManager.stopBluetoothSco();
audioManager.setBluetoothA2dpOn( (audioFlags & allowBlueToothA2DP) != 0 );
audioManager.setMode( AudioManager.MODE_NORMAL );
} else
r = true; // BOF!
return r;
}
That's why I think the microphone "controller/driver" of the BQ X2 could be freeze occasionally.
Okay, I'm testing all these changes.
I have two windows:
I guess I should: 1ยบ Do the changes in the main project. 2ยบ Clean a run the demo project
That's right?
Yes, the develop environment that you downloaded is linked to the tau_core project (inside this environment). No external dependencies. You can make your changes and just run the demo.
The demo/example will compile the tau_core project. You do not need two windows.
Myself, I use the project flutter_sound/example/android/ (a java project) under Android Studio instead of flutter_sound/example/ (a Flutter project) when I want to debug Android.
But you do not really debug so both are OK
Testing the zip where you did the changes the application crashes when pressing the GO button on BQ M10:
I/flutter (11101): FS:---> openAudioSession
D/AudioManager(11101): setMicrophoneMute: on = false
E/AndroidRuntime(11101): FATAL EXCEPTION: main
E/AndroidRuntime(11101): Process: com.dooboolab.example, PID: 11101
E/AndroidRuntime(11101): java.lang.NoClassDefFoundError: Failed resolution of: Landroid/media/AudioFocusRequest$Builder;
E/AndroidRuntime(11101): at com.dooboolab.TauEngine.FlautoSession.setAudioFocus(FlautoSession.java:144)
E/AndroidRuntime(11101): at com.dooboolab.TauEngine.FlautoPlayer.initializeFlautoPlayer(FlautoPlayer.java:120)
E/AndroidRuntime(11101): at com.dooboolab.fluttersound.FlutterSoundPlayer.initializeFlautoPlayer(FlutterSoundPlayer.java:174)
E/AndroidRuntime(11101): at com.dooboolab.fluttersound.FlutterSoundPlayerManager.onMethodCall(FlutterSoundPlayerManager.java:85)
E/AndroidRuntime(11101): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/AndroidRuntime(11101): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/AndroidRuntime(11101): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:738)
E/AndroidRuntime(11101): at android.os.MessageQueue.nativePollOnce(Native Method)
E/AndroidRuntime(11101): at android.os.MessageQueue.next(MessageQueue.java:328)
E/AndroidRuntime(11101): at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime(11101): at android.app.ActivityThread.main(ActivityThread.java:5726)
E/AndroidRuntime(11101): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11101): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
E/AndroidRuntime(11101): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
E/AndroidRuntime(11101): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.media.AudioFocusRequest$Builder" on path: DexPathList[[zip file "/data/app/com.dooboolab.example-2/base.apk"],nativeLibraryDirectories=[/data/app/com.dooboolab.example-2/lib/arm64, /data/app/com.dooboolab.example-2/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
E/AndroidRuntime(11101): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(11101): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(11101): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(11101): ... 14 more
E/AndroidRuntime(11101): Suppressed: java.lang.ClassNotFoundException: android.media.AudioFocusRequest$Builder
E/AndroidRuntime(11101): at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(11101): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(11101): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(11101): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(11101): ... 15 more
E/AndroidRuntime(11101): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
In BQ X2, Samsung S9 and Moto G9 works fine ๐๐ผ
I guess it is normal, BQ M10 uses Android 6 (API level 23) and in the commented code I see:
if ( Build.VERSION.SDK_INT >= 26 )
So forget that crash ๐ All working ๐๐ผ
hum
SDK compatibility on Android is a nightmare
Remember without editing setAudioFocus
method it worked fine in Android 6.
This change also works in all devices: int audioSource = MediaRecorder.AudioSource.MIC
Sincerely I think everything is ok. The BQ X2 microphone controller was freeze. If it happens again I'll check the native recorder before reboot it.
But right now the released version works fine.
Do you mean that we do not have to change anything in V 7.4.14 ? This is bad, because I am sure there is something to fix in this area. You had problem. Several other users had problem too...
The minimum I will do, will be to add this instruction to Mute OFF. Actually τ does not handle the muting ON/OFF so this is no problem to ensure that the muting is OFF.
And probably I am going to split setAudioFocus() in two procedures :
I am thinking that I cannot wait that the new API will be released. I have actually too many tasks to do before cleaning the API, and I really do not like how setAudiofocus works (this procedure is called during openAudioSession, both for the Recorder and the Player).
Flutter Sound Version :
Released version
Version number: ^7.4.14+1
FULL flavor
Result of the command "flutter pub deps | grep flutter_sound"
Severity
Platforms you faced the error
Logs
When recording:
When playing the sound:
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.