NateRickard / Plugin.AudioRecorder

Audio Recorder plugin for Xamarin and Windows
MIT License
164 stars 68 forks source link

play() not working on Xiaomi devices #53

Open OmPals opened 4 years ago

OmPals commented 4 years ago

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.

MennoG commented 4 years ago

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.

OmPals commented 4 years ago

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

ghost commented 4 years ago

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.

gimenezfrg commented 3 years ago

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.

alfred11235 commented 3 years ago

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...

jaysonragasa commented 3 years ago

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.

mattiascibien commented 3 years ago

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 commented 3 years ago

Guys check out #64 for the updated code

sb111111111 commented 2 years ago

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

mattiascibien commented 2 years ago

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.

josecfvalente commented 2 years ago

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

mattiascibien commented 2 years ago

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