I aimed to record audio, save it to Firebase storage, and then retrieve and play it on the Home Screen. To accomplish this, I followed these steps.
For Upload file :
Future<String> storeAudio(String recordFilePath) async {
String downloadURL = "failed";
File audioFile = File(recordFilePath);
Reference reference = FirebaseStorage.instance
.ref('try/')
.child('/${DateTime.now().millisecondsSinceEpoch.toString()}');
try {
SettableMetadata metadata = SettableMetadata(contentType: 'audio/mpeg');
await reference.putFile(audioFile, metadata);
downloadURL = await reference.getDownloadURL();
print("Upload complete, File URL: $downloadURL");
} on FirebaseException catch (e) {
print("Failed to upload audio: ${e.message}");
} catch (e) {
print("An unexpected error occurred: $e");
}
return downloadURL;
}
It saves like this:
Download URL of audio : this
Now, I tried to play in Home Screen using audioplayers: ^5.1.0
flutter package
Play Audio :
AudioPlayer audioPlayer = AudioPlayer();
await audioPlayer.play(UrlSource(
'https://firebasestorage.googleapis.com/v0/b/rotaract-debate.appspot.com/o/try%2F1699343040392.mp3?alt=media&token=af9657b6-e495-4165-922d-015668b9fcc7&_gl=1*ikbc29*_ga*NzI2NjMxMDE3LjE2ODU3Njg1OTY.*_ga_CW55HF8NVT*MTY5OTMzMjkyNS4zNDEuMS4xNjk5MzQ0MDU2LjU4LjAuMA..'));
It shows erorr -
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(AndroidAudioError, Failed to set source. For troubleshooting, see: https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md, MEDIA_ERROR_UNKNOWN {what:1}, MEDIA_ERROR_SYSTEM, null)
But, It works properly on another URLs like this "https://listringtones.com/tones/wp-content/uploads/2023/10/2bewafaa-tu.mp3"
What's the wrong?