Add to example project: Play mp3 from local assets using just_audio with audio_service
To which pages does your suggestion apply?
- https://github.com/ryanheise/audio_service/blob/master/example/lib/main.dart
Quote the sentences(s) from the documentation to be improved (if any)
n/a
Describe your suggestion
A working example of playing a local asset using just_audio and audio_service would be helpful.
In the audio_service example project, it would be cool to see a third MediaItem added to MediaLibrary's _items property, where the id of the third MediaItem is path to local asset (like "asset:///audio/nature.mp3" in the just_audio example project)
I don't have any issues when playing an asset using just_audio alone. But when I try to do what I described above, I get "Operation Stopped" when setting the audio source to an mp3 from assets.
I only saw open issues for loading Art from assets, so I assumed this is working and I'm just doing something wrong.
...
I think the playing of mp3s is more of an issue for just_audio, but note that the just_audio example already shows how to load from assets.
I don't have any issues when playing an asset using just_audio alone. But when I try to do what I described above, I get "Operation Stopped" when setting the audio source to an mp3 from assets.
I would be interested to know more about this, do you have a reproduction project?
Hi Ryan, I realized this is only an issue with iOS simulator. It works fine on an iOS device. Works fine in Android emulator. And works on Android device.
Here's a reproduction project below. I forked audio_service and in the example project, I swapped out the first MediaItem in MediaLibrary for a local asset (asset:///audio/nature.mp3). Pubspec.yaml is updated to include the asset.
https://github.com/headfulness/audio_service
Thank you
We can close this issue. There was enough documentation between the two libraries to figure it out. The error on iOS simulator just confused me.
Let me know if the iOS simulator problem should be opened as a separate issue.
Hmm, that's interesting. So assets work but not in the first position of a playlist? I'll reopen until I can investigate this. Even though it may only happen in the Simulator, I suspect there's a random element to it and it could manifest on a real device by chance.
It happens when playing an asset in any position in the playlist.
In my reproduction project I switched the playlist to play the HTTP AudioSource first, asset second. The url plays fine, then once the asset starts, there is a log for "Operation Stopped" and the audio doesn't play. I'll debug it a bit tonight and see where it's coming from.
Edit: here's the log [VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: PlatformException(-11849, Operation Stopped, null, null)
Hmm, so is this bug reproducible in the example, which includes an asset? I have never encountered this error myself on the Simulator.
Yeah I modified the example project in audio_service to reproduce it. The fork is below.
https://github.com/headfulness/audio_service
Interestingly, it worked on ios simulator last night. So there must be a timing or environment aspect causing it. I'm working a lot with assets right now so I'll see if I can find out what the trigger is.
There is a known issue where assets can fail if you don't await the loading process before you try to play it, and in the example app there is no await because each action is driven by user interaction.
If you have control over such things in your app, you might try doing await player.setAsset(...); before playing (or whatever set method you use instead).
thank you, I will implement that