How to play audio in flutter? | Play an Audio from Local Asset | Android Studio

2 years ago
2

✅✅ If you found this video useful then like this video
🖍Kindly Write your feedback in comments

=============================================

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

https://pub.dev/packages/audioplayers...

Create a folder named asset and put an audio file in it.
Open the pubspec.yaml file and add the folder location where the audio is.
assets:
- assets/

open the main.dart file and import the audioplayers package.
import 'package:audioplayers/audioplayers.dart';

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

Run and Click the button.

)) notice if you are using audioplayers: 1.0.1

use:
final player=AudioPlayer();
player.setSource(AssetSource('theme_01.mp3'));

Loading comments...