I am using microphone package to record voice, Flutter stores audio for a while we can play as Audio url that but i need to store the voice url in form of file in firebase storage. heare my code....
void handleAudioState(AudioState state) {
setState(() {
if (audioState == AudioState.not) {
// Starts recording
try{
_recorder.start();
audioState = AudioState.recording;
}
catch(e){
print(e.toString());
}
// Finished recording
}
else if (audioState == AudioState.recording) {
audioState = AudioState.play;
_recorder.stop();
// Play recorded audio
}
else if (audioState == AudioState.play) {
audioState = AudioState.stop;
dynamic rec=_recorder.toBytes();
print(rec.toString());
// var file= File.fromRawPath(rec);
//print(file);
_audioPlayer=AudioPlayer();
_audioPlayer.setUrl(_recorder.value.recording!.url).then((value){
print(_recorder.value.recording!.url);
return _audioPlayer.play().then((value){
setState(() {
audioState = AudioState.play;
});
});
});
// Stop recorded audio
} else if (audioState == AudioState.stop) {
audioState = AudioState.play;
_audioPlayer.stop();
}
});
}
void handleAudioState(AudioState state) {
setState(() {
if (audioState == AudioState.not) {
// Starts recording
try{
_recorder.start();
audioState = AudioState.recording;
}
catch(e){
print(e.toString());
}
// Finished recording
} else if (audioState == AudioState.recording) {
audioState = AudioState.play;
_recorder.stop();
// Play recorded audio
} else if (audioState == AudioState.play) {
audioState = AudioState.stop;
dynamic rec=_recorder.toBytes();
print(rec.toString());
// var file= File.fromRawPath(rec);
//print(file);
_audioPlayer=AudioPlayer();
_audioPlayer.setUrl(_recorder.value.recording!.url).then((value){
print(_recorder.value.recording!.url);
return _audioPlayer.play().then((value){
setState(() {
audioState = AudioState.play;
});
});
});
// Stop recorded audio
} else if (audioState == AudioState.stop) {
audioState = AudioState.play;
_audioPlayer.stop();
}
});
}
i am using below Packages just_audio: ^0.8.0 microphone: please let me know how to do this , thanks in anticipation
Aucun commentaire:
Enregistrer un commentaire