Background
I've succeeded uploading an audio file (3gp) into Google-Drive.
Now I want to be able to play the file within the app.
The Google Drive API only allows to get the input stream of the file that's stored there.
The problem
All MediaPlayer capabilities of inputs aren't available in my case, which is only InputSteam:
I know I can save the file from the Google-Drive to the cache and play it, but I want to avoid the storage handling, and play the file on the fly.
What I've tried
I tried to search for this issue, and only found that it might be possible using AudioTrack (here). It might also be possible using new Jelly-Bean features (shown here, found from here), but I'm not sure as it's quite low level.
Sadly, using AudioTrack I got wrong sounds being played (noise).
I've also noticed that MediaPlayer has the option to set the dataSource to be MediaDataSource (here) , but not only I'm not sure how to use it, it also requires API 23 and above.
Of course, I tried using a url that is given in Google-Drive, but this is only used for other purposes and isn't being directed to the audio file, so it can't be used using MediaPlayer.
The question
Given an InputStream, is it possible to use AudioTrack or something else, to play an audio 3gp file ?
Is there maybe a support library solution for this?
1 Answers
Answers 1
If your minSdkVersion
is 23 or higher, you can use setDataSource(MediaDataSource)
and supply your own subclass of the abstract
MediaDataSource
class.
For older devices, you should be able to use a pipe created from ParcelFileDescriptor
. You would have a thread that writes data to your end of the pipe, and pass the FileDescriptor
(from getFileDescriptor()
) for the player's end to setDataSource(FileDescriptor)
.
0 comments:
Post a Comment