florent37 / Flutter-AssetsAudioPlayer

Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications
https://pub.dartlang.org/packages/assets_audio_player
Apache License 2.0
752 stars 357 forks source link

using Assets_Audio_player for playing audio file #833

Closed NegarTavakol closed 4 months ago

NegarTavakol commented 4 months ago

Flutter Version

My version : 3.19.5

Lib Version

My version :

Platform (Android / iOS / web) + version

Platform : android

Describe the bug

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

class AudioPlayer extends StatefulWidget { final String audioPath;

const AudioPlayer({Key? key, required this.audioPath}) : super(key: key);

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

class AudioPlayerState extends State { final AssetsAudioPlayer _assetsAudioPlayer = AssetsAudioPlayer(); bool _isPlaying = false;

@override void initState() { super.initState(); _initAudioPlayer(); }

@override void dispose() { _assetsAudioPlayer.dispose(); super.dispose(); }

Future _initAudioPlayer() async { await _assetsAudioPlayer.open(Audio(widget.audioPath), autoStart: false); _assetsAudioPlayer.isPlaying.listen((isPlaying) { setState(() { _isPlaying = isPlaying; }); }); }

@override Widget build(BuildContext context) { return ElevatedButton( style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Colors.indigoAccent), shape: MaterialStateProperty.all( CircleBorder(), ), ), onPressed: () { if (_isPlaying) { _assetsAudioPlayer.pause(); } else { _assetsAudioPlayer.play(); } }, child: Icon( _isPlaying ? Icons.pause : Icons.play_arrow, size: 32, color:Colors.orangeAccent, ), ); } } here when I pressed button to playing Audio file some of them is played some other no . I try to change codec to that filies which this package can play but these errors still remain could you tell me how can I fix it?

errors: com.github.florent37.assets_audio_player.playerimplem.PlayerFinder$NoPlayerFoundException W/System.err(30120): at com.github.florent37.assets_audio_player.playerimplem.PlayerFinder._findWorkingPlayer(PlayerFinder.kt:70) W/System.err(30120): at com.github.florent37.assets_audio_player.playerimplem.PlayerFinder._findWorkingPlayer(PlayerFinder.kt:88) W/System.err(30120): at com.github.florent37.assets_audio_player.playerimplem.PlayerFinder.access$_findWorkingPlayer(PlayerFinder.kt:26) W/System.err(30120): at com.github.florent37.assets_audio_player.playerimplem.PlayerFinder$_findWorkingPlayer$1.invokeSuspend(Unknown Source:15) W/System.err(30120): at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) W/System.err(30120): at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) W/System.err(30120): at android.os.Handler.handleCallback(Handler.java:938) W/System.err(30120): at android.os.Handler.dispatchMessage(Handler.java:99) W/System.err(30120): at android.os.Looper.loop(Looper.java:246) W/System.err(30120): at android.app.ActivityThread.main(ActivityThread.java:8653) W/System.err(30120): at java.lang.reflect.Method.invoke(Native Method) W/System.err(30120): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) W/System.err(30120): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

seventyrun commented 4 months ago

hello @NegarTavakol try changing this line: from this:

await _assetsAudioPlayer.open(Audio(widget.audioPath), autoStart: false);

to this:

await _assetsAudioPlayer.open(Audio.file(widget.audioPath), autoStart: false);

Tell me if there is any improvement

NegarTavakol commented 4 months ago

@seventyrun hi ,thanks so much for your answer, I chanced based on your commend but It has still the same error : I/ExoPlayerImpl(23734): Release f7c011b [ExoPlayerLib/2.18.1] [a70q, SM-A705FN, samsung, 30] [goog.exo.core, goog.exo.exoplayer, goog.exo.decoder, goog.exo.datasource] V/MediaPlayer-JNI(23734): native_setup V/MediaPlayerNative(23734): constructor V/MediaPlayerNative(23734): setListener V/MediaPlayer-JNI(23734): reset V/MediaPlayerNative(23734): reset V/MediaPlayer(23734): resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false V/MediaPlayer(23734): cleanDrmObj: mDrmObj=null mDrmSessionId=null V/MediaPlayer(23734): resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false V/MediaPlayer(23734): cleanDrmObj: mDrmObj=null mDrmSessionId=null V/MediaPlayer-JNI(23734): release V/MediaPlayerNative(23734): setListener V/MediaPlayerNative(23734): disconnect V/MediaPlayerNative(23734): destructor V/MediaPlayerNative(23734): disconnect W/System.err(23734): com.github.florent37.assets_audio_player.playerimplem.PlayerFinder$NoPlayerFoundException W/System.err(23734): at com.github.florent37.assets_audio_player.playerimplem.PlayerFinder._findWorkingPlayer(PlayerFinder.kt:70) W/System.err(23734): at com.github.florent37.assets_audio_player.playerimplem.PlayerFinder._findWorkingPlayer(PlayerFinder.kt:88) W/System.err(23734): at com.github.florent37.assets_audio_player.playerimplem.PlayerFinder.access$_findWorkingPlayer(PlayerFinder.kt:26) W/System.err(23734): at com.github.florent37.assets_audio_player.playerimplem.PlayerFinder$_findWorkingPlayer$1.invokeSuspend(Unknown Source:15) W/System.err(23734): at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) W/System.err(23734): at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) W/System.err(23734): at android.os.Handler.handleCallback(Handler.java:938) W/System.err(23734): at android.os.Handler.dispatchMessage(Handler.java:99) W/System.err(23734): at android.os.Looper.loop(Looper.java:246) W/System.err(23734): at android.app.ActivityThread.main(ActivityThread.java:8653) W/System.err(23734): at java.lang.reflect.Method.invoke(Native Method) W/System.err(23734): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) W/System.err(23734): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) I/flutter (23734):