Just_audio: Can't load audio file from assets folder

Created on 11 Aug 2020  Â·  8Comments  Â·  Source: ryanheise/just_audio

Which API doesn't behave as documented, and how does it misbehave?

Can't load audio file from assets folder.

Version : just_audio: ^0.3.1

AudioPlayer audioPlayer = AudioPlayer();
await audioPlayer.setAsset("assets/sounds/forest_birds.ogg");
await audioPlayer.play();

Minimal reproduction project
you can reproduce it with the simple project with below code snippet.

AudioPlayer audioPlayer = AudioPlayer();
await audioPlayer.setAsset("assets/sounds/forest_birds.ogg");
await audioPlayer.play();

To Reproduce
Steps to reproduce the behaviour:
-> Run above code snippet with example project

Error messages

2020-08-11 19:49:11.972 13781-13864/com.example.flutter_app E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Unable to load asset: /sounds/forest_birds.ogg
    #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
    <asynchronous suspension>
    #1      UriAudioSource._loadAsset (package:just_audio/just_audio.dart:1050:29)
    <asynchronous suspension>
    #2      UriAudioSource._setup (package:just_audio/just_audio.dart:1030:38)
    <asynchronous suspension>
    #3      AudioPlayer._load (package:just_audio/just_audio.dart:405:20)
    #4      AudioPlayer.load (package:just_audio/just_audio.dart:381:30)
    #5      AudioPlayer.setAsset (package:just_audio/just_audio.dart:368:7)
    #6      SoundRepo.addSoundToQueue (package:flutter_app/repository/soundrepo.dart:39:23)
    #7      CubitSound.addSoundToQueue (package:flutter_app/bloc/cubit_sound.dart:16:17)
    #8      _HomeState.onSoundSelected (package:flutter_app/ui/home.dart:42:33)
    #9      _HomeState.build.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter_app/ui/home.dart:115:33)
    #10     GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
    #11     TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
    #12     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5)
    #13     BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:254:7)
    #14     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
    #15     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
    #16     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
    #17     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
    #18     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
    #19     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
    #20     _rootRunUnary (dart:async/zone.dart:1196:13)
    #21     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
    #22     _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
    #23     _invoke1 (dart:ui/hooks.dart:275:10)
    #24     _dispatchPointerDataPacket (dart:ui/hooks.dart:184:5)

Expected behavior
Should load audio file from assets

Smartphone (please complete the following information):

  • Device: POCO F1
  • OS: Android 10

Flutter SDK version

[√] Flutter (Channel stable, v1.17.5, on Microsoft Windows [Version 10.0.18362.959], locale en-US)
    • Flutter version 1.17.5 at F:\temp\flutter
    • Framework revision 8af6b2f038 (6 weeks ago), 2020-06-30 12:53:55 -0700
    • Engine revision ee76268252
    • Dart version 2.8.4
1 backlog bug please complete all sections of the issue template

All 8 comments

It appears that you deleted some important sections from your bug report (as per the instructions, please don't delete these, they are required.)

I have the same problem. In _loadAsset the parameter assetPath always starts with a leading slash and rootbundle.load does not like a leading slash (maybe a absolute/relative path problem).

Furthermore, there is a problem in AudioPlayer.setAsset

  1. player.setAsset("sounds/background.mp3"); tries to load "background.mp3", not "sounds/background.mp3".

  2. player.setAsset("/sounds/background.mp3"); tries to load "/sounds/background.mp3", which is not accessible by rootbundle.load.

If i modify your source and strip the leading slash before rootbundle.load, at least "/sounds/background.mp3" works, but this is not the regular flutter asset style.

Sorry if i missed the guideline, but this is my first contribution.

Hi @derToralf if you can post your own "complete" bug report and I will act on it quickly.

Hi @derToralf if you can post your own "complete" bug report and I will act on it quickly.

I have updated complete information and bug report i had.

@Alphabets007 can you please fill in the deleted section "Minimal Reproduction Project"? This is the main thing that I need before I can take time off the other bugs I'm fixing and turn my attention to this one. Thanks.

@Alphabets007 a code snippet is not a minimal reproduction project.

I'll close this (regretfully) as an invalid bug report. Hopefully someone will post a valid bug report, and once that happens, I will be happy to act on it promptly (provided I am not sleeping at that time). But right now, I am going to work on fixing other bugs. As they say, please help me help you.

This can happen if you spell the path wrong or if you don't declare your assets in pubspec.yaml.

https://stackoverflow.com/a/67209597/3681880

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ReaganRealones picture ReaganRealones  Â·  9Comments

jjb182 picture jjb182  Â·  10Comments

suragch picture suragch  Â·  9Comments

smkhalsa picture smkhalsa  Â·  6Comments

slimyTextBox picture slimyTextBox  Â·  3Comments