audioplayer icon indicating copy to clipboard operation
audioplayer copied to clipboard

How to play from assets in flutter app

Open anuranBarman opened this issue 5 years ago • 6 comments

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'

anuranBarman avatar Sep 09 '18 16:09 anuranBarman

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)

cnqiuxue avatar Dec 27 '18 10:12 cnqiuxue

somebody help solve this issue please

maheshj01 avatar Dec 28 '18 07:12 maheshj01

same here... anyone know how

BwesShr avatar Jan 22 '19 15:01 BwesShr

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

xiaolongwuhpu avatar Jan 24 '19 08:01 xiaolongwuhpu

https://stackoverflow.com/questions/51901558/play-a-custom-sound-in-flutter

serkandyck avatar Apr 26 '19 23:04 serkandyck

I guess ogg doesn't support..

shinriyo avatar Sep 16 '19 13:09 shinriyo