Plugin.AudioRecorder icon indicating copy to clipboard operation
Plugin.AudioRecorder copied to clipboard

play() not working on Xiaomi devices

Open OmPals opened this issue 3 years ago • 12 comments

I have tested these functions on several devices that are Redmi Note 7, Redmi Y1, Vivo V5 and iPhone6. I found that audio recording feature works fine. The recorded audio file is being stored as well. But player function is not working on Redmi note 7 and Redmi Y1. On other devices, it works well. The code is same as stated in the sample application.

Thank you.

OmPals avatar Jul 05 '20 07:07 OmPals

I have a similar issue, but using an OnePlus 6 with Android 10.0. First I thought it was because of Android 10.0. But in the simulator with Android 10.0 it works fine. Also tested on a Samsung Galaxy 5 with Android 9. There it works fine.

MennoG avatar Aug 07 '20 05:08 MennoG

Yes. The same code works on UWP. I've spent almost a week testing on Xiaomi phones. Maybe some problem with these devices.

OmPals avatar Aug 07 '20 06:08 OmPals

I tested on LG G6 with Android 8 and it works fine. But on Samsung S20 Ultra and OnePlus with Android 10, the devices dont play audio.

ghost avatar Aug 30 '20 22:08 ghost

I have the same problem. I may be mistaken, but the problem seems to be because of the format (.wav).

I can't play the recorded file on any external player on Xiaomi phones, on others I can.

gimenezfrg avatar Oct 01 '20 02:10 gimenezfrg

I also have a similar problem on a redmi note 8, I can't play the recorded audio, but also the sample app doesn't recognize silences, I have to manually stop the recording...

alfred11235 avatar Nov 18 '20 23:11 alfred11235

Not working on Xiaomi Redmi Note 9 Pro either. Anyone found a solution? I tried using Samsung S8 using Android 9 and it's working fine.

jaysonragasa avatar Apr 01 '21 01:04 jaysonragasa

The problem on this devices arises from the fact that the code in WaveRecorder is wrong as it overwrites the first bytes of audio data with the header (stream Writes do not insert, but replace). I guess that since the header is not correct with the size of the file on some platforms this causes problems reading the file.

I fixed this by changing the OnBroadcast by making it write on a MemoryStream instead of the file and then StopRecording is changed roughly as follows:

private void StopRecorder()
		{
			try
			{
				if (_audioStream != null)
				{
					_audioStream.OnBroadcast -= OnStreamBroadcast;
					_audioStream.OnActiveChanged -= StreamActiveChanged;

                    using (var fileStream = new FileStream(_filePath, FileMode.Create, FileAccess.Write))
					{
						using (var fileWriter = new BinaryWriter(fileStream, Encoding.UTF8))
						{
							//now that audio is finished recording, write a WAV/RIFF header at the beginning of the file
							AudioFunctions.WriteWavHeader(fileWriter, _audioStream.ChannelCount, _audioStream.SampleRate,
							_audioStream.BitsPerSample, _byteCount);
							_memoryAudioStream.Seek(0, SeekOrigin.Begin);
							_memoryAudioStream.CopyTo(fileStream);
						}
                    }
                }
			}

Sorry if I am not clear but it's the end of the day and I spent one full day on this.

mattiascibien avatar Apr 12 '21 15:04 mattiascibien

Guys check out #64 for the updated code

mattiascibien avatar Apr 13 '21 07:04 mattiascibien

Hi folks how did you manage to use this? The NuGet package hasn't been updated so I'm not sure how to get these changes into my project

sb111111111 avatar Jul 28 '22 19:07 sb111111111

Hi folks how did you manage to use this? The NuGet package hasn't been updated so I'm not sure how to get these changes into my project

I suggest you use the source direcly. This project is abandoned.

mattiascibien avatar Jul 29 '22 07:07 mattiascibien

@mattiascibien can you explain how to use a source directly in a pcl project, thanks.

josecfvalente avatar Aug 04 '22 09:08 josecfvalente

@josecfvalente donwload the full project form github and add all the .cs files in visual studio. Simple as that.

mattiascibien avatar Aug 04 '22 09:08 mattiascibien