ExoPlayer stuttering with url from a specific site - android

So, my app plays radio stations from the Internet. And all is fine except of playing radio stations from 101.ru. Music is stuttering and I can't say that there are any equal time intervals between stutters.
I'm using ExoPlayer library v2.8.0.
What have I tried to fix it:
To update ExoPlayer to 2.10.3 - no result
To experiment with the buffer size of Exoplayer - no result or worst (few hours of experiments)
My code of ExoPlayer init:
IcyHttpDataSourceFactory factory = new IcyHttpDataSourceFactory.Builder(Util.getUserAgent(context, userAgent))
.setIcyHeadersListener(this)
.setIcyMetadataChangeListener(this).build();
dataSourceFactory = new DefaultDataSourceFactory(context, null, factory);
RenderersFactory renderersFactory = new DefaultRenderersFactory(context);
TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());
DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl);
player.addListener(this);
My code of ExoPlayer play from url:
player.prepare(generateMediaSource(Uri.parse(url)));
private MediaSource generateMediaSource(Uri uri) {
return new ExtractorMediaSource.Factory(dataSourceFactory)
.setExtractorsFactory(new DefaultExtractorsFactory())
.createMediaSource(uri);
}
So, 101.ru has about 80 radio stations and about 95% of them are stuttering. However, other 100-200 radio stations have an excellent quality.
What can I do to fix it? Thanks

The issue have been resolved. Problem was in IcyHttpDataSourceFactory. I've wrote in exoplayer github issues and there I've got an answer:
Version should be 2.10.3 and you shouldn't to use any other IcyHttpDataSourceFactory because they added ICY support in the latest release.
So, stuttering was resolved and sound is clear now.

Related

How to play 5.1 audio in exoplayer android smart phone

I would like to play DD 5.1 Audio in my android app based on exoplayer. when i try to play video via my app it shows blank and audio is muted but same video and audio is playing via MX player or vlc player.
please let me know how to make my app support DD5.1 audio
image for supporting issue
MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(Uri.parse(url)));
ExoTrackSelection.Factory videoTrackSelectionFactory = new
AdaptiveTrackSelection.Factory();
trackSelector = new
DefaultTrackSelector(Player.this, videoTrackSelectionFactory);
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this);
renderersFactory.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER);
simpleExoPlayer = new SimpleExoPlayer.Builder(this, renderersFactory)
.setTrackSelector(trackSelector)
.setSeekForwardIncrementMs(10000)
.setSeekBackIncrementMs(10000)
.build();
playerView.setPlayer(simpleExoPlayer);
playerView.setKeepScreenOn(true);

Play HLS radio without player view in my Android app

I am developing an android app to play the HLS radio. I don't want to have a player view since there is no video track for the streaming. I want to control the audio playing by a play/pause button.
I did some google search and I found that there is a google official project called ExoPlayer which seems to have a feature of playing hls. I tried the example but it shows that it does not support the audio codec. Therefore, I wonder if there is any solution of
an example of Exoplayer for playing HLS audio in android app without any player view
any other solution to achieve my goal
Thank you!
Edited on 11th, May
The following part is my code, though it seems to be a deprecated method
DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();
String userAgent = Util.getUserAgent(MainActivity.this, "ExoPlayerDemo");
DefaultDataSourceFactory mediaDataSourceFactory = new DefaultDataSourceFactory(MainActivity.this, BANDWIDTH_METER,
new DefaultHttpDataSourceFactory(userAgent, BANDWIDTH_METER));
HlsMediaSource mediaSource = new HlsMediaSource.Factory(mediaDataSourceFactory)
.createMediaSource(Uri.parse(url), null, null);
TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory);
DefaultRenderersFactory renderersFactory =
new DefaultRenderersFactory(MainActivity.this, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER);
ExoPlayer player = ExoPlayerFactory.newSimpleInstance(MainActivity.this, trackSelector);
player.setPlayWhenReady(true);
if(mediaSource!=null) {
player.prepare(mediaSource);
}
I will try using the example code from official site with a player ui and I will use a layout to overlap on the ui. I will be grateful if there is any other suggestion.

seekTo(mTimeMilis) won't work properly when using ConcatenatingMediaSource in ExoPlayer

I have more than one video to play one by one. After Creating MediaSource of each video, All these are going to ConcatenatingMediaSource(mediaSources[]). Normally it play one by one. But when video is fast forward using seekTo(), 1st video is ok but other videos do not follow seekTo().
Suppose 1st video is 10s, 2nd 12s, 3rd 10s.
If I call seekTo((long)12*1000) it should play 2nd video with 2s forward. But it plays from the beginning of 2nd video.
Setting VideoSources
DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(),Util.getUserAgent(getApplicationContext(), "ExoPlayer"));
MediaSource mediaSource = new ExtractorMediaSource.Factory(defaultDataSourceFactory).createMediaSource(videoItem.getVideoUri());
videoItemArrayList.get(k).setVideoSource(mediaSource);
Concatenate Sources
MediaSource[] mediaSources = new MediaSource[videoItemArrayList.size()];
int j=0;
for(VideoItem item : videoItemArrayList){
mediaSources[j] = item.getVideoSource();
++j;
}
concatenatedSource = new ConcatenatingMediaSource(mediaSources);
Setup exoplayer
exoPlayer.prepare(concatenatedSource);
exoPlayer.seekTo(0);
exoPlayer.setPlayWhenReady(true);
exoPlayer.getPlaybackState();
Using exoplayer.seekTo(period) internally calls currentWindowIndex() internally of the source. While you are playing the first video in the concatenated mediasource you end up receiving windowIndex as 0. Use seekTo(windowIndex, time) to solve the issue.

android exoplayer implementation for m3u8 live streming [duplicate]

This question already has answers here:
Exoplayer adaptive hls streaming
(2 answers)
Closed 5 years ago.
I am new to android development in eclipse ( because my computer is low config PC ).
I will try making tv application like stream .m3u8 files over network. how to archive this with exoplayer?
It is very confusing to me.
m3u or m3u8 is a file type for media playlists, that's it. The content is going to be in the format HLS
HLS is:
HTTP-based media streaming communications protocol implemented by Apple Inc
(but non Apple products can stream it)
Here is a tutorial, https://possiblemobile.com/2016/03/hls-exoplayer/ but it's for an old version of exoplayer (because exoplayer has been going through lots of changes lately).
Here is a working version I use to play m3u8 files (MyURL is a http link to an m3u8 (playlist) file:
First initiate the player:
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoFactory);
LoadControl loadControl = new DefaultLoadControl();
// Create Player
player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl);
Then add the HlsMediaSource
Handler mHandler = new Handler();
String userAgent = Util.getUserAgent(this, "User Agent");
DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(
userAgent, null,
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
1800000,
true);
HlsMediaSource mediaSource = new HlsMediaSource(MyURL, dataSourceFactory, 1800000,
mHandler, null);
player.setPlayWhenReady(true);
player.prepare(mediaSource);
Using HLS, for m3u8 is a lot like using exoplayer with the default MediaSource, except you should use the HlsMediaSource instead

How to get started with ExoPlayer

My requirement is very simple. I've a database in www.xyz.example.com. Using web service I pull the detail of a song/songs. I store them in an Arraylist.
The arraylist contains the url of the song. When user press play button, the url is passed to a service and song starts playing. I've successfully implemented android's default MediaPlayer. But I noticed that it takes too long to prepare. Then I found that Exoplayer is there to replace MediaPlayer. Now I notice that ExoPlayer is not as simple as Mediaplayer. It has so many classes, implementation etc. etc..
I added the latest player in my project using gradle
compile 'com.google.android.exoplayer:exoplayer:r2.0.0'
Now what should I do? How to actually intialize the Exoplayer? According to developer guide
// 1. Create a default TrackSelector
Handler mainHandler = new Handler();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
new DefaultTrackSelector(mainHandler, videoTrackSelectionFactory);
I cannot get anything here. What is a BandwidthMeter here? What is TrackSelection here ? What is TrackSelector here ?
Again...
// 2. Create a default LoadControl
LoadControl loadControl = new DefaultLoadControl();
// 3. Create the player
SimpleExoPlayer player =
ExoPlayerFactory.newSimpleInstance(context, trackSelector, loadControl);
Here these are some another confusions. What is the difference between Exoplayer and SimpleExoPlayer ?
Moreover, I see that most of the projects using ExoPlayer in Github are about playing video over http. How can I achieve my above stated goal? (Please do not advice me to read the demo app. It is not simple.) Can anyone guide me to create a audio player.

Categories

Resources