'Flutter audioplayers error (1, -19) - No audio is played and the app doesn't crash
I am trying to use the flutter audioplayers package to play audio files and am getting this error. While following an online flutter tutorial I had this exact code and it ran and produced sound correctly, but now it doesn't play audio. I think maybe there is a change in my IDE settings or a change on my computer, but I don't know how to find the issue.
E/MediaPlayerNative(13949): error (1, -19)
E/MediaPlayer(13949): Error (1,-19)
E/MediaPlayerNative(13949): stop called in state 0, mPlayer(0xb4e843c0)
E/MediaPlayerNative(13949): error (-38, 0)
V/MediaPlayer(13949): resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(13949): cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer(13949): resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(13949): cleanDrmObj: mDrmObj=null mDrmSessionId=null
Here is the code I'm using to test the audioplayers package.
import 'package:flutter/material.dart';
import 'package:audioplayers/audio_cache.dart';
void main() => runApp(XylophoneApp());
class XylophoneApp extends StatelessWidget {
final player = AudioCache();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child: FlatButton(
color: Colors.red,
onPressed: () {
player.play('note1.wav');
},
child: Text('Click Me'),
),
),
),
),
);
}
}
Solution 1:[1]
AudioPlayer audioPlayer;
AudioCache audioCache = AudioCache();
String url = 'images/PID_meditation_demo_novoice.mp3'; //local mp3 file in asset folder
playLocal() async {
audioPlayer = await audioCache.play(url); //audio play function
}
pauseAudio() async { // audio pause
await audioPlayer.pause();}
resumeAudio() async {
await audioPlayer.resume(); //audio resume
}
stopAudio() async {
if(audioPlayer !=null){
await audioPlayer.stop(); //audio srope
}
}
Solution 2:[2]
i faced the same issue , and no solution works for me , until i changed the package , check this one , it's very nice and works without any problem . assets_audio
playQRScannerSound() async {
AssetsAudioPlayer.newPlayer().open(
Audio("assets/audios/scan_Beep.mp3"),
autoStart: true,
);
}
I hope it help you , best of luck .
Solution 3:[3]
Yes, i actually have same error, but i try this:
final playerx = new AudioCache(fixedPlayer: AudioPlayer());
then on my action:
playerx.fixedPlayer.stop();
playerx.play('turn2.mp3');
i most stop stream my mplayer before i start it. and that make error gone from the world..
Solution 4:[4]
I don't know if you've fixed your issue or not. I had the same issue, The choice that I had and possibly yourself was to get a different package or connect your own phone instead of emulator, I found when I connected my own phone (galaxy note9) I had no problems anymore ?.
Solution 5:[5]
Solved it by adding "mode" and "stayAwake" as follows:
await audioPlayer.play("audio/buttonOn.mp3",
mode: PlayerMode.LOW_LATENCY,
stayAwake: false);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Johny Saini |
Solution 2 | Ravindra S. Patil |
Solution 3 | Dzakfi Azhar |
Solution 4 | Anthony Ricketts |
Solution 5 | Dharman |