Skip to content

Instantly share code, notes, and snippets.

@tanmaybaranwal
Last active February 22, 2017 11:40
Show Gist options
  • Save tanmaybaranwal/718e3993d32bb501f04015c72104f7e4 to your computer and use it in GitHub Desktop.
Save tanmaybaranwal/718e3993d32bb501f04015c72104f7e4 to your computer and use it in GitHub Desktop.
ExoPlayer DASH Media is not playing in Samsung Galaxy Duos 4.1.2
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
/**
* Created by tanmaybaranwal on 14/02/17.
*/
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.LoadControl;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.dash.DashMediaSource;
import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource;
import com.google.android.exoplayer2.trackselection.AdaptiveVideoTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.util.Util;
public class ExoPlayerActivity extends Activity {
// Variables
private static String VIDEO_URI =
"http://dash.edgesuite.net/akamai/bbb_30fps/bbb_30fps.mpd";
private SimpleExoPlayer player;
private SimpleExoPlayerView simpleExoPlayerView;
private Handler mainHandler;
private TrackSelection.Factory videoTrackSelectionFactory;
private TrackSelector trackSelector;
private LoadControl loadControl;
private DataSource.Factory dataSourceFactory;
private MediaSource videoSource;
private Uri uri;
private String userAgent;
private static final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
// Activity onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.exo_player_activity);
simpleExoPlayerView = (SimpleExoPlayerView)findViewById(R.id.player_view);
userAgent = Util.getUserAgent(this,"SimpleDashExoPlayer");
createPlayer();
attachPlayerView();
preparePlayer();
}
public void createPlayer(){
mainHandler = new Handler();
videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
loadControl = new DefaultLoadControl();
player = ExoPlayerFactory.newSimpleInstance(this,trackSelector,loadControl);
}
public void attachPlayerView(){
simpleExoPlayerView.setPlayer(player);
}
public void preparePlayer(){
uri = Uri.parse(VIDEO_URI);
dataSourceFactory = buildDataSourceFactory(bandwidthMeter);
videoSource = new DashMediaSource(uri,buildDataSourceFactory(null),new DefaultDashChunkSource.Factory(dataSourceFactory),mainHandler,null);
//videoSource = new ExtractorMediaSource(uri,
//buildDataSourceFactory(null), new DefaultExtractorsFactory(), null, null);
player.prepare(videoSource);
}
private DataSource.Factory buildDataSourceFactory(DefaultBandwidthMeter bandwidthMeter){
return new DefaultDataSourceFactory(this, bandwidthMeter, buildHttpDataSourceFactory(bandwidthMeter));
}
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter){
return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}
@Override
public void onStop(){
super.onStop();
player.release();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment