Reputation: 5968
I have a custom AudioPlayer
class to handle playing audio in my app, and it uses the android MediaPlayer
class under the hood.
It currently has a method play(source: MediaDataSource)
. This needs to take in some generic source object that it can play, so I decided to use MediaDataSource
which seems right.
How do I obtain a MediaDataSource
from a resource, e.g. R.raw.my_audio_file
, so that my custom AudioPlayer
class can use it? Or is MediaDataSource
the wrong type to use here, and if so what other type should I use?
Upvotes: 0
Views: 115
Reputation: 13541
One possiblity is to use:
The string path for local resources/assets could probably be translated to a path/URI via: how to get an uri of an image resource in android
And if you have web endpoints this would also work for that as well.
Upvotes: 1