Reputation: 998
Is there any possible way to record an audio and upload to a server using xamarin forms. The best result I got after searching was this https://github.com/HoussemDellai/UploadFileToServer
The library used in the solution supports only Image and Video.
Thanks in advance
Upvotes: 0
Views: 1741
Reputation: 32775
Is there any possible way to record an audio and upload to a server using xamarin forms.
There are many ways realizing this feature. For recording an audio within Xamarin.Forms, you could use Plugin.AudioRecorder
to realize. Fore more you could refer the following code.
private AudioRecorderService _recoder;
protected override void OnAppearing()
{
_recoder = new AudioRecorderService
{
StopRecordingOnSilence = true,
StopRecordingAfterTimeout = true,
AudioSilenceTimeout = TimeSpan.FromSeconds(60)
};
_recoder.AudioInputReceived += _recoder_AudioInputReceived;
}
private void _recoder_AudioInputReceived(object sender, string e)
{
// do some stuff
}
private async void Button_Clicked(object sender, EventArgs e)
{
await RecodAudio();
}
private async Task RecodAudio()
{
try
{
if (!_recoder.IsRecording)
{
await _recoder.StartRecording();
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
private async void StopButton_Clicked(object sender, EventArgs e)
{
if (_recoder.IsRecording)
{
await _recoder.StopRecording();
}
}
For uploading file, you could use the UploadFileToServer
that mentioned in your case. And you will get the audio file path in the AudioInputReceived
event args.
private void _recoder_AudioInputReceived(object sender, string e)
{
var path = e;
}
Upvotes: 0