ExoPlayer Cant Play some audio streams - android

i am newbie here. i am developing a android app to listen to online radio stations.
problem i am getting here is ExoPlayer(2.9.2) can or cant play some streams of same type of different bitrates.
For Example
These mpga streams
http://108.61.34.50:7130/ ---> 96kbs ===> Playable
http://s3.voscast.com:8408 ---> 64kbs ===> Not Playable
http://220.247.227.20:8000/citystream ---> 128kbs ===> Not Playable
i used vlc codec window to get this information, and those 3 streams share same values other than bitrate.
i am using ExtractorMediaSource
songs.add(Uri.parse("http://220.247.227.20:8000/citystream"));//City
player= ExoPlayerFactory.newSimpleInstance(this,
new DefaultTrackSelector());
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "AudioApp"));
ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource();
for (Uri temp : songs)
{
BaseMediaSource mediaSourse=
new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(temp);
concatenatingMediaSource.addMediaSource(mediaSourse);
}
player.prepare(concatenatingMediaSource);
player.setPlayWhenReady(true);
Hope anyone can help me out..

After testing various different streams, i realized that this is a device specific error.
Huawei Y5 2017
the other phone's that i tested work pretty well and i ended up submiting issue to ExpoPlayer team on github without knowing this is device specific issue.
Here it is
Why does ExoPlayer cant play some of the streams of same type with different bitrates ?

Related

Android - Exoplayer shows blank screen while rendering mpd video

I am using following test stream to render mpd in android exoplayer
https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/mpds/11331.mpd
following is my exoplayer code:
val adaptiveTrackSelection = AdaptiveTrackSelection.Factory()
val trackSelector: TrackSelector = DefaultTrackSelector(mContext!!, adaptiveTrackSelection)
mConcatenatingMediaSource = ConcatenatingMediaSource()
val mediaItem = MediaItem.Builder().setUri(url).setMimeType(MimeTypes.APPLICATION_MPD)
.build()
val dashMediaSource = DashMediaSource.Factory(DefaultDataSourceFactory(mContext!!, mContext!!.packageName))
.createMediaSource(mediaItem)
mConcatenatingMediaSource.addMediaSource(dashMediaSource)
exoPlayer = SimpleExoPlayer.Builder(this).setTrackSelector(trackSelector).build()
.also { exoPlayer ->
exoPlayer.playWhenReady = true
exoPlayer.addMediaSource(mConcatenatingMediaSource as MediaSource)
playerView!!.player = exoPlayer
exoPlayer.prepare()
attachEventListener(exoPlayer)
}
I am getting player state STATE_READY, I am getting position update for each second and finally player state STATE_ENDED as well, but on screen it is always a blank screen. I am testing on samsung device with os android 12.
Can anyone please help me solve this issue.
The link you have shared is to a DRM protected video stream and the behaviour you are seeing is consistent with the player not displaying encrypted content.
If you just want to test ExoPlayer in general then you can simple choose a different stream which is not DRM protected.
If you do want to test this particular stream then you will need to set up the DRM information in ExoPLayer.
The ExoPlayer documentation provides guidance on this including the example below (https://exoplayer.dev/drm.html):
MediaItem mediaItem = new MediaItem.Builder()
.setUri(videoUri)
.setDrmConfiguration(
new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID)
.setLicenseUri(licenseUri)
.setMultiSession(true)
.setLicenseRequestHeaders(httpRequestHeaders)
.build())
.build();
This is for Widevine which is the default DRM on Android and which your stream supports. You can see this by looking in the manifest you linked to and you will see the Widevine UUID listed in a Content protection element.
ContentProtection schemeIdUri="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
As an FYI, the full list of DRM UUID's is here: https://dashif.org/identifiers/content_protection/

Android Exo Player - Trouble playing Video on Demand from API

I'm working with the Pac-12 API (college sports data) and trying to make a streaming video player.
The Pac-12 API (http://api.pac-12.com/v3/vod?page=0") gives back a list of video objects with urls for their Video's on Demand (VODs).
I have exo player set up in Android and it's working for videos with urls that end in .mp4.
But when I try to plug in the VOD urls it's giving an error that it cannot extract the file type.
I'm using exo player 2.8.4 which may or may not be the problem. But the newer version of exo player ( 2.9.0 and above ) has min sdk 26 (which my testing phone doesn't run).
I'm working on checking if that's the problem, but in the mean time I wanted to post this question in case anyone can help.
Here is my exo player set up. mediaUrl is the varaible that works with .mp4 but not the VOD url.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(
context, Util.getUserAgent(context, "RecyclerView VideoPlayer"));
String mediaUrl = mediaObjects.get(targetPosition).getMedia_url();
if (mediaUrl != null) {
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(mediaUrl));
videoPlayer.prepare(videoSource);
videoPlayer.setPlayWhenReady(true);
}
The VOD urls give no file type extension at the end, so I tried concatenating '.vod' onto the mediaUrl varaible, but no luck with that.
From reading around online it seems like VODs are supported by exo player, but I can't find much about how the setup might be different.
Heres a direct link to one of the Pac-12 VODs. This is the same url as what the API returns.
https://pac-12.com/videos/oregons-dana-altman-talks-andy-katz-about-recruitment-getting-fans-back-and-more

Play multiple URL at once in Android

How to play multiple URLs sequentially in android? I have a small streaming url 10s/each of one complete song. I need to play it one after another. Is there any way doing it so the music don't get lagged?
https://exoplayer.dev/media-sources.html read Advanced composition
MediaSource firstSource =
new ProgressiveMediaSource.Factory(...).createMediaSource(firstVideoUri);
MediaSource secondSource =
new ProgressiveMediaSource.Factory(...).createMediaSource(secondVideoUri);
// Plays the first video twice, then the second video.
ConcatenatingMediaSource concatenatedSource =
new ConcatenatingMediaSource(firstSource, firstSource, secondSource);
It looks like you are using the m3u8 playlist to play with MediaPlayer. However, you wouldn't able to do it. You can use ExoPlayer to play m3u8 list. Check this link
https://github.com/google/ExoPlayer
simpleExoPlayerView.setShowMultiWindowTimeBar(true);

An AAC audio stream is playable in VLC for Android, but not in Exoplayer

I have an RTMP stream I want to play in my app using the Exoplayer library. My setup for that is as follows:
TrackSelector trackSelector = new DefaultTrackSelector();
RtmpDataSourceFactory rtmpDataSourceFactory = new RtmpDataSourceFactory(bandwidthMeter);
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
factory = new ExtractorMediaSource.Factory(rtmpDataSourceFactory);
factory.setExtractorsFactory(extractorsFactory);
createSource();
mPlayer = ExoPlayerFactory.newSimpleInstance(mActivity, trackSelector, new DefaultLoadControl(
new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE),
1000, // min buffer
3000, // max buffer
1000, // playback
2000, //playback after rebuffer
DefaultLoadControl.DEFAULT_TARGET_BUFFER_BYTES,
true
));
vwExoPlayer.setPlayer(mPlayer);
mPlayer.addListener(mVideoStreamHandler);
mPlayer.addVideoListener(new VideoListener() {
#Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
Log.d("hasil", "onVideoSizeChanged: w:" + width + ", h:" + height);
String res = width + "x" + height;
resolution.setText(res);
}
#Override
public void onRenderedFirstFrame() {
}
});
Where createSource() is as follows:
private void createSource() {
mMediaSource180 = factory.createMediaSource(Uri.parse(API.GAME_VIDEO_STREAM_URL_180));
mMediaSource360 = factory.createMediaSource(Uri.parse(API.GAME_VIDEO_STREAM_URL_360));
mMediaSource720 = factory.createMediaSource(Uri.parse(API.GAME_VIDEO_STREAM_URL_720));
mMediaSourceAudio = factory.createMediaSource(Uri.parse(API.GAME_AUDIO_STREAM_URL));
}
My current problem is that only the first three ExtractorMediaSources work fine in Exoplayer. The mMediaSourceAudio refuses to play in Exoplayer, but works just fine in the VLC Media Player for Android.
Right now I have a suspicion that the format is AAC-LTP, or whatever AAC variant that requires a codec available in VLC but not in default Android. However, I do not have access to the encoding process so I don't know for sure.
If this isn't the case, what is it?
EDIT:
I've been debugging the BandwidthMeter and added a MediaSourceEventListener. When I use the normal Video sources, onDownstreamFormatChanged() gets called, but not when I use that Audio Stream source.
In addition, the BandwidthMeter works fine, with bytes always downloaded in all parts of the stream and more bytes when the video stream comes in, but only in the Audio only stream that, when I call mPlayer.getBufferedPosition(), the returned value is always 0. Also, when I use the Audio Stream source, no OMX code was called - no decoders were set up.
Am I seeing a malformed audio stream, or do I need to change my Exoplayer's settings?
EDIT 2:
Further debugging reveals that, in all the Video streams and Audio stream, the same FlvExtractor is used. Even though the Video streams have the avc video track encoding and mp4a-latm audio track encoding. Is this normal?
Turns out it's because the stream was recognized to have two tracks/sampleQueues. One Audio track, and one track with null format. That null track was supposed to be the video track, which was supposed to exist according to the stream's flvHeader flag.
For now, I get around this by creating a custom MediaSource using a custom MediaPeriod. Said custom MediaPeriod having code to separate the video and audio tracks of the SampleQueues, then using the audio-only SampleQueue[] instead of the source SampleQueue[] when I want to play the audio-only stream.
Though this gives me another point of concern: There's something one can do to alter the 'has audio track (flag & 0x04) and video track (flag & 0x01)' flag in the rtmp stream, right?
Thanks for the comments, I'm new to ExoPlayer. But your comments helped me in debugging and getting multiple workarounds to the issue.
I tried to use custom MediaSource and custom MediaPeriod to address this audio issue. I have observed video format data coming after audio data incase of video+audio wowza stream, so the function maybeFinishPrepare() will wait for getting both video and audio format tag data before invoking onPrepared, incase if video tagData is received first. Incase of audio data received first, it wont wait and will call onPrepare().
With the above changes, I was able to play audio alone and video_audio wowza streams, where rtmp tagHeader with tagTypes were coming in the order of video tagData and then followed by audio data.
I wasn't able to use the same patch with srs server to play both audio_only and video_audio streams with the same changes. srs server is giving tagData in the order of audio and then video tagData,
So, I debugged further in FlvExtractor. In readFlvHeader, I have overriden the hasAudio and hasVideo variables. These variables will be set based on the first few tagHeaders(5 or 6). I used peekFully on input for 6 times in a loop. In each loop after fetching tagType and tagDataSize, tagDataSize is used to input.advancePeekPosition(), and tagType is used to identify whether we have audio/video format data in tagData. After peeking for first 6 consecutive tagHeaders, I was able to get actual values of hasAudio and hasVideo, and ignored the flvHeaders.flags, which were used to set these variables.
Custom FlvExtractor workaround, looked cleaner than custom MediaSource/MediaPeriod, as we will create those many tracks as necessary, as we are setting proper hasVideo/hasAudio values.

how to add multiple subtitles in Exo Player 2

I want to show subtitles with ExoPlayer 2 . users can choose between languages (English,German, or Arabic) . Video links are HLS (.m3u8) and subtitles are .str files .
I couldn't find any samples to do this.
is there any sample?
The link I added as a comment to your original post will be how you'll build the UI around text track selection. Then to actually get the tracks to be added to your mp4 file (or whatever the format is), you'll want to use a MergingMediaSource. The simple version looks like so:
MediaSource videoSource = new ExtractorMediaSource(videoUri, ...);
MediaSource subtitleSource = new SingleSampleMediaSource(subtitleUri, ...);
// Plays the video with the sideloaded subtitle.
MergingMediaSource mergedSource = new MergingMediaSource(videoSource, subtitleSource);
You can merge multiple subtitle tracks into the video source. Many different file formats are accepted.
I got that particular code sample from this blog post - but I believe that same code is also in the ExoPlayer documentation. That code block combined with the sample code that I link to in my other answer here should be enough to get you some subtitles.
Please let me know if that works for you.

Categories

Resources