Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

play() not working on Xiaomi devices #53

Open
OmPals opened this issue Jul 5, 2020 · 12 comments
Open

play() not working on Xiaomi devices #53

OmPals opened this issue Jul 5, 2020 · 12 comments

Comments

@OmPals
Copy link

OmPals commented Jul 5, 2020

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 OmPals changed the title play() not working on Xiomi devices play() not working on Xiaomi devices Jul 5, 2020
@MennoG
Copy link

MennoG commented Aug 7, 2020

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
Copy link
Author

OmPals commented Aug 7, 2020

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

@OmPals OmPals closed this as completed Aug 7, 2020
@OmPals OmPals reopened this Aug 7, 2020
@ghost
Copy link

ghost commented Aug 30, 2020

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

Guys check out #64 for the updated code

@sb111111111
Copy link

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
Copy link

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
Copy link

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

@mattiascibien
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants