flutter

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

  • 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
    }
    }