add sound to my flutter app
import 'package:audioplayers/audio_cache.dart';import 'package:audioplayers/audioplayers.dart';
add sound to my flutter app
import 'package:audioplayers/audio_cache.dart';import 'package:audioplayers/audioplayers.dart';
flutter button playing sound
void main() => runApp(HomePage());
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
AudioCache _audioCache;
@override
void initState() {
super.initState();
// create this only once
_audioCache = AudioCache(prefix: "audio/", fixedPlayer: AudioPlayer()..setReleaseMode(ReleaseMode.STOP));
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text("Music play")),
body: RaisedButton(
onPressed: () => _audioCache.play('my_audio.mp3'),
child: Text("Play Audio"),
),
),
);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us