Flutter-AssetsAudioPlayer icon indicating copy to clipboard operation
Flutter-AssetsAudioPlayer copied to clipboard

Audio Doesnt stop the second time after playing it

Open shabeenabarde opened this issue 4 years ago • 0 comments

My Flutter version : 2.2.3

My Library version : assets_audio_player: ^3.0.3+6

Platform : Android.

My Issue: **Kindly find piece of my code below. I have implemented this package and it works fine. But Lets say when I click the first button called 'Play', the audio starts and when I click the button 'Stop', it works fine.

Now the second time, when I click the 'Play' button again, the audio starts again but when I click on 'Stop' button, the audio doesn't stop. Why is that?**

import 'package:assets_audio_player/assets_audio_player.dart'; import 'package:flutter/material.dart';

void main() { runApp(SoundTest()); }

class SoundTest extends StatefulWidget { SoundTest({Key key}) : super(key: key);

@override _SoundTestState createState() => _SoundTestState(); }

class _SoundTestState extends State<SoundTest> { final assetsAudioPlayer = AssetsAudioPlayer();

soundtest() { assetsAudioPlayer.open(Audio("sounds/alert.mp3")); assetsAudioPlayer.play(); }

@override void dispose() { assetsAudioPlayer?.dispose(); super.dispose(); }

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Test'), ), body: Column( children: [ RaisedButton( onPressed: () { soundtest(); }, child: Text("Play")), RaisedButton( onPressed: () { assetsAudioPlayer.stop(); }, child: Text("Stop")), ], )); } }

shabeenabarde avatar Nov 08 '21 12:11 shabeenabarde