Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to play an InputStream using Exoplayer? #1086

Closed
amanmj opened this issue Dec 23, 2015 · 6 comments
Closed

How to play an InputStream using Exoplayer? #1086

amanmj opened this issue Dec 23, 2015 · 6 comments
Labels

Comments

@amanmj
Copy link

amanmj commented Dec 23, 2015

I have used exoplayer to play audio files and stream over http.
But I can't find any interface that implements SampleSource whose constructor has an inputstream as a parameter. Please help me with this.

@ojw28
Copy link
Contributor

ojw28 commented Dec 23, 2015

DataSource is the interface through which ExoPlayer reads media data, so that's the interface that you'd need to find a suitable implementation of. We do not provide an implementation that wraps an InputStream directly because the InputStream interface doesn't provide suitable random access behavior for media playback, which is required both for seeking and because some media formats place data at the end of the file that must be read at the start of playback.

However, where you're able to create InputStream instances at a given offset into the data, or where you know that InputStream.skip will behave in an efficient way for the type of InputStream that you're handling, it is possible to implement a DataSource around InputStream instances. AssetDataSource and ContentDataSource are two examples for reading assets and data from content providers respectively.

Where are your InputStream instances coming from exactly, and where is the media located that you're trying to play? Knowing that would help suggest a suitable approach.

@ojw28 ojw28 added the question label Dec 23, 2015
@amanmj
Copy link
Author

amanmj commented Dec 23, 2015

Media is located on a server , I am creating an inputstream on the client side and I was using audiotrack to play the stream, but I want to shift to exoplayer to play this stream. Is there any way?

@ojw28
Copy link
Contributor

ojw28 commented Dec 23, 2015

To put it another way, why are you trying to use an InputStream as opposed to just giving ExoPlayer the URL directly? InputStream is not a suitable interface for full featured media playback.

@amanmj
Copy link
Author

amanmj commented Dec 27, 2015

@ojw28
For some reasons I will have to stick to streaming from an InputStream.
I created my own DataSource similar to ContentDataSource where I changed the statement :
inputStream = new FileInputStream(assetFd.getFileDescriptor());

to my empty inputStream.
But I am getting an exception each time I try to play the track while streaming :

Internal track renderer error.
com.google.android.exoplayer.ExoPlaybackException: com.google.android.exoplayer.extractor.ExtractorSampleSource$UnrecognizedInputFormatException: None of the available extractors (WebmExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, TsExtractor, FlvExtractor) could read the stream. at com.google.android.exoplayer.SampleSourceTrackRenderer.maybeThrowError(SampleSourceTrackRenderer.java:154)

Any idea how to fix this?

@ojw28
Copy link
Contributor

ojw28 commented Dec 27, 2015

If you're feeding content from the InputStream directly into the AudioTrack then the data being provided by the InputStream is probably unpackaged and decompressed audio. ExoPlayer handles packaged and compressed media.

It's very unclear what the goals are here. What's wrong with your existing AudioTrack based solution? Given the apparent constraints (unpackaged and decompressed media through an InputStream), there's not really a huge amount that a library like ExoPlayer could do beyond feeding the data into an AudioTrack, which is what you're doing yourself already.

The constraints themselves sounds flawed/bad, although without knowing the exact use case it's hard to say. I'd suggest revisiting those, and if they really are sensible, sticking with an AudioTrack based solution.

@ojw28 ojw28 closed this as completed Dec 27, 2015
@amanmj
Copy link
Author

amanmj commented Jan 20, 2016

@ojw28 since there was not datasource available that takes a raw inputstream as a source,
I created this project. Here I have created my own custom datasource (similar to AssetDataSource).
I have feeded myInputStream (my custom build InputStream) instead of

"assetManager.open(path, AssetManager.ACCESS_RANDOM);" as in assetDataSource.

My project plays a song named "song.mp3" present in the root directory of SD Card.
It creates an inputStream from the file and simulating a read speed of 20 KiloBytes Per Second, thus creating a buffer speed of 20 KBPS which can be changed by manipulating "BUFFER_BYTES".
Please review my code 👍
https://github.com/amanmj/InputStream_Player

@google google locked and limited conversation to collaborators Jun 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants