How to play audio in flutter? | Audio File From Asset | Tutorial audioplayers package

preview_player
Показать описание

audio player from url

We can add audio players dependency in pubspec .yaml .
audioplayers: ^0.20.1

Create a folder named asset and put an audio file in it.
assets:
- assets/

Add a button and include the code to play the audio in the onpress event.
final player = AudioCache();

Run and Click the button.
---------------------------------------------
if you are using audioplayers: 1.0.1

use:
final player=AudioPlayer();

Want to add audio to your Flutter app? Check out this tutorial on using the audioplayers package to play audio files from your app's assets. Learn how to control playback with buttons, loop audio, and more!
Whether you're building a music player or just need to add sound effects to your app, this tutorial on playing audio in Flutter has got you covered. Follow along and learn how to load audio files from your app's assets and control playback using the audioplayers package.
Flutter makes it easy to add audio to your mobile apps, and this tutorial will show you how. You'll learn how to use the audioplayers package to play audio files from your app's assets, including how to set up a basic audio player UI and control playback.
If you're building an app that requires audio playback, you'll want to check out this tutorial on playing audio in Flutter. Using the audioplayers package, you'll learn how to load audio files from your app's assets and control playback with custom buttons and a seek bar.
Ready to add some sound to your Flutter app? This tutorial will teach you how to play audio files from your app's assets using the audioplayers package. Follow along and learn how to set up a basic audio player UI, control playback, and display the current playback time.
Рекомендации по теме
Комментарии
Автор

I didn't expect that kind of music lol amazing 🤣

vamsikandula
Автор

where is the documentation of the audio player? I couldn't find it on dart package manager website

gauravshinde
Автор

Could you please show us the easiest way to add sound loop function? Thanks

MrIMacro
Автор

Hey how can I add this to play without the buttons but when I press the button it mutes?

shukrans
Автор

please how to implement speaker and mute with audio

abdelmalekaniba
Автор

Gives Error "The method 'play' isn't defined for the type 'AudioCache'."

azmi
Автор

you are great
thank you so much


but noticed in the video that you use this version of this package
audioplayers: ^0.20.1

cause the last package doesn't have the play method

khaledhisham
Автор

hey my android doenst recognize mp3 files pls how did you do yours

kinghunter
Автор

if (estado == true) {
final player = AudioCache();
player.play("alarma.mp3");
} else {
¿ How to stop ?
}

pieromantilla
Автор

Didn't play at all and shows no error
Trying to solving this problem from 4 days
Stucked man

clovisstanford
Автор

Thanks bruh. But In my case the instance of AudioCache doesn't have any play method.

socialcodia
Автор

player.play('cheering.wav');

"The method 'play' isn't defined for the type 'AudioCache'. (Documentation) "

"_handleInput(HurdleProvider provider) {
if (!provider.isAValidWord) {
showsnackbarMsg(context, 'Not a word in my dictionary');
return;
}
if {
provider.checkAnswer();
}
if (provider.wins) {
showResult(
context: context,
title: 'You Win!!!',
body: 'The word was ${provider.targetWord}',
onPlayAgain: () {
Navigator.pop(context);
provider.reset();
},
onNextLevel: () {},
onCancel: () {
Navigator.pop(context);
},
);
player.play('cheering.wav');"

bobdaawid