audioplayer
audioplayer copied to clipboard
How to play from assets in flutter app
I have added a mp3 file in asset and trying to play it as local file from the play method. But it is not getting played. what can be the reason? I am also getting the error of 'E/MediaPlayerNative(12813): start called in state 0, mPlayer(0x0) E/MediaPlayerNative(12813): Attempt to call getDuration in wrong state: mPlayer=0x0, mCurrentState=0'
me too. W/MediaPlayer(29597): See the documentation of setAudioStreamType() for what to use instead with android.media.AudioAttributes to qualify your playback use case W/bz.rxla.flutter/audio(29597): Invalid DataSource W/bz.rxla.flutter/audio(29597): java.io.IOException: setDataSource failed. W/bz.rxla.flutter/audio(29597): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1187) W/bz.rxla.flutter/audio(29597): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1160) W/bz.rxla.flutter/audio(29597): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1127) W/bz.rxla.flutter/audio(29597): at bz.rxla.audioplayer.AudioplayerPlugin.play(AudioplayerPlugin.java:108) W/bz.rxla.flutter/audio(29597): at bz.rxla.audioplayer.AudioplayerPlugin.onMethodCall(AudioplayerPlugin.java:46) W/bz.rxla.flutter/audio(29597): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:200) W/bz.rxla.flutter/audio(29597): at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163) W/bz.rxla.flutter/audio(29597): at android.os.MessageQueue.nativePollOnce(Native Method) W/bz.rxla.flutter/audio(29597): at android.os.MessageQueue.next(MessageQueue.java:325) W/bz.rxla.flutter/audio(29597): at android.os.Looper.loop(Looper.java:142) W/bz.rxla.flutter/audio(29597): at android.app.ActivityThread.main(ActivityThread.java:6494) W/bz.rxla.flutter/audio(29597): at java.lang.reflect.Method.invoke(Native Method) W/bz.rxla.flutter/audio(29597): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440) W/bz.rxla.flutter/audio(29597): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
somebody help solve this issue please
same here... anyone know how
it worked on exoplayer, flutter project assets File Directory is
assets/flutter_assets/assets/testmusic.mp3 , maybe help you,
- the real path is assets/xxx.ogg
-
if (mMusicUrl.startsWith('assets')) mMusicUrl = mMusicUrl.replaceFirst("assets/", "asset:///flutter_assets/assets/");
hope this helps
https://stackoverflow.com/questions/51901558/play-a-custom-sound-in-flutter
I guess ogg doesn't support..