Ad
I Couldn't Trigger Sound Alert After User's Action On Flutter (based On Kotlin Error After AudioPlayers Package Added)
I'm working on a Flutter project for an Android application. I need to give sound alerts when the user's action is completed success or wrong.
I've tried the AudioPlayers package but it didn't work.
version: audioplayers: ^0.20.1
playMusic() async {
await audioPlayer.play(url, isLocal: true);
}
I even couldn't build the project after adding audioplayers.
Is there any other package for this?
Ad
Answer
When I added to AudioPlayers package to pubseck.yaml It was giving Kotlin error.
First I change my Kotlin version to 1.5.10 from 1.30.50 in 'android/build.gradle'.
ext.kotlin_version = '1.5.10'
And then the app started to give multidex errors.
I changed the configuration of 'android/app/build.gradle' like below
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.allstore_mobile"
minSdkVersion 20
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
After the above changes, the AudioPlayers package started to work.
final AudioCache _audioCache = AudioCache(
prefix: 'assets/sounds/',
fixedPlayer: AudioPlayer()..setReleaseMode(ReleaseMode.STOP),
);
_audioCache.play('success.mp3');
Ad
source: stackoverflow.com
Related Questions
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?
Ad