How can i download my audios from FirebaseStorage in flutter app? - flutter

if can anyone write the code to run in flutter version 3.7.3 please i will be so appreciated
How can i download my audios from FirebaseStorage in flutter app and show them in ListView and make bottom to play them for know i have liek 10000 audios in my firebase_storage please some help if so❤

If you are geting a Url or audio file the you can simple pass the url of your audio file in package: audioplayer
Code:
AudioPlayer audioPlayer = AudioPlayer(mode: PlayerMode.LOW_LATENCY);
play() async {
int result = await audioPlayer.play(url);
if (result == 1) {
// success
}
}
for more controll and custumization you can also use : audio_service:

Related

Audio Players is not working, AVPlayerItem.Status.failed iOS

I'm trying to use the plugin Audio Players for my recorded audios ( it's working perfectly for android ) but when I try to play the audio I get this error:
"iOS => call setVolume, playerId 57c0b5cc-3c75-4f8f-bf99-ad8ddbcb7709"
"iOS => call setUrl, playerId 57c0b5cc-3c75-4f8f-bf99-ad8ddbcb7709"
""
2022-06-23 18:27:00.168194-0300 Runner[16264:695114] flutter: AVPlayerItem.Status.failed
Any idea of what can I do to solve this problem?
await audioPlayer2.setVolume(1.0);
await audioPlayer2.setUrl(filepath, isLocal: true);
await audioPlayer2.play(filepath, isLocal: true);
audioPlayer2.onPlayerStateChanged.listen((event) {
setState(() {
_isPlaying = false;
});
Instead of using setUrl and then play I only used this:
final _audioPlayer = AudioPlayer()..setReleaseMode(ReleaseMode.stop);
await _audioPlayer.play(UrlSource(widget.postData.audioURL));
you have to add capabilities in xcode
Go to xcode -> runner -> add capabilities
Inter-App Audio
Thanks

Flutter - cannot download audio files

It's been 3 days that I try to fix an issue with the download of audio files with my Flutter application. When I try to download audio files, the request keep the "pending" status and finish with no error.
I have research a lot and find something about the contentLength of the client who is always at 0 but it doesn't help.
Now I have tried to make a get request to a website with sample audio files and it doesn't work too. I have tested via Postman and it always work.
My function:
Future<void> _download(String url, String filepath) async {
final response = await this.get("https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_700KB.mp3");// await this.get("$baseURL$url");
log("Try to get audio files: ${response.isOk}");
if (response.isOk) {
File file = File(filepath);
final raf = file.openSync(mode: FileMode.write);
response.bodyBytes.listen((value) {
raf.writeFromSync(value);
}, onDone: () {
log("closed $filepath");
raf.closeSync();
});
}
}
The response.isOk is always false.
I used GetConnect from GetX package who used httpClient.
Via Dart devtools I obtain this from the request:
https://prnt.sc/1q3w33z
https://prnt.sc/1q3x9ot
So I used another package: Dio and now it works.

Any API documentation for the Cast package?

so I recently got started with the flutter package cast in order to communicate with Chromecast devices. But I couldn't find any details on how to use it. If you could give me some help in actually playing a media file such as a song or a video that would be wholesome!
My current code:
CastSession session;
Future<void> _connect(BuildContext context, CastDevice object) async {
session = await CastSessionManager().startSession(object);
session.stateStream.listen((state) {
if (state == CastSessionState.connected) {
// Close my custom GUI
Navigator.pop(context);
_sendMessage(session);
}
});
session.messageStream.listen((message) {
print('receive message: $message');
});
}
// My video playing code
session.sendMessage(CastSession.kNamespaceReceiver, {
'type': 'MEDIA',
'link': 'http://somegeneratedurl.com',
});
Ok, so I found a solution to the answer. There is unfortunately no command to play a video file. I've looked through the Gcast protocol reference and there is no command for playing video files. I found this package that can cast videos, and I'm gonna use that package instead.

Looking for a good sample working code for downloading any file from URL in flutter. If its with native downloader then this will be very good

Looking for a good sample working code for downloading any file from URL in flutter. If its with native downloader then this will be very good. Please help me with sample of code to download any file using native downloader in flutter.
I have used few libraries but didn't turned out well.
For a mobile device, I used the http package to download a file to the applications document directory
First, create a httpClient object
static var httpClient = new HttpClient();
Then you can create a function like this to download the file:
Future<void> _downloadFile({
required String fileName,
}) async {
String url = ...;
var request = await httpClient.getUrl(Uri.parse(url));
var response = await request.close();
var bytes = await consolidateHttpClientResponseBytes(response);
String dir = (await getApplicationDocumentsDirectory())!.path;
File file = new File('$dir/$fileName'); // Note: Filename must contain the extension of the file too, like pdf, jpg etc.
await file.writeAsBytes(bytes);
}
For a flutter web application, I felt the url_launcher package was the easiest to work with.
_launchURL() async {
String url = ...;
if (await canLaunch(url)) {
await launch(url);
print('URL Launcher success');
} else {
throw Exception('Could not launch $url');
}
}
The url_launcher package code works even for a mobile device but it opens a new browser window to download the required file which is not a good user experience so I have used 2 approaches for the same problem.
Hope I have answered your query.

How to send a voice message using flutter?

Actually I need to send a voice message to my contacts using flutter.I have searched a lot.But I didn't get any idea on this.Is there any way to do this.?
if you want to share a voice message in a chat(e.g firebase chat) you can use flutter_sound, send a voice file to your cloud, and you can play it again with flutter_sound too.
You can use the audio_recorder package:
https://pub.dev/packages/audio_recorder
// Import package
import 'package:audio_recorder/audio_recorder.dart';
// Check permissions before starting
bool hasPermissions = await AudioRecorder.hasPermissions;
// Get the state of the recorder
bool isRecording = await AudioRecorder.isRecording;
// Start recording
await AudioRecorder.start(path: _controller.text, audioOutputFormat: AudioOutputFormat.AAC);
// Stop recording
Recording recording = await AudioRecorder.stop();
print("Path : ${recording.path}, Format : ${recording.audioOutputFormat}, Duration : ${recording.duration}, Extension : ${recording.extension},");