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

Find Simple ExoPlayer Example #2210

Closed
lioun1729 opened this issue Dec 16, 2016 · 6 comments

Comments

@lioun1729
Copy link

commented Dec 16, 2016

My object implements Simple ExoPlayer for DASH Stream

So, I try to find simple exoplayer example (using basic exoplayer library and method)

but I can't find that..

Please help, The demo app code is too hard to me

@ojw28 ojw28 added the question label Dec 16, 2016

@lioun1729

This comment has been minimized.

Copy link
Author

commented Dec 17, 2016

I implemented simple dash stream player using SimpleExoPlayer API

Add My code this comment, soon

@lioun1729

This comment has been minimized.

Copy link
Author

commented Dec 18, 2016

Here is my code

This code is very simple example for playing one Dash Stream (by Big Bunny MPD)

// Variables
private static final String VIDEO_URI =
        "http://www-itec.uni-klu.ac.at/ftp/datasets/DASHDataset2014/BigBuckBunny/4sec/BigBuckBunny_4s_onDemand_2014_05_09.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.activity_dash_play);
    simpleExoPlayerView = (SimpleExoPlayerView)findViewById(R.id.player_view);
    userAgent = Util.getUserAgent(this,"SimpleDashExoPlayer");
    createPlayer();
    attachPlayerView();
    preparePlayer();
}

// Create TrackSelection Factory, Track Selector, Handler, Load Control, and ExoPlayer Instance
public void createPlayer(){
    mainHandler = new Handler();
    videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
    trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    loadControl = new DefaultLoadControl();
    player = ExoPlayerFactory.newSimpleInstance(this,trackSelector,loadControl);
}

// Set player to SimpleExoPlayerView
public void attachPlayerView(){
    simpleExoPlayerView.setPlayer(player);
}

// Build Data Source Factory, Dash Media Source, and Prepare player using videoSource
public void preparePlayer(){
    uriParse();
    dataSourceFactory = buildDataSourceFactory(bandwidthMeter);
    videoSource = new DashMediaSource(uri,buildDataSourceFactory(null),new DefaultDashChunkSource.Factory(dataSourceFactory),mainHandler,null);
    player.prepare(videoSource);
}

// Parse VIDEO_URI and Save at uri variable
public void uriParse(){
    uri = Uri.parse(VIDEO_URI);
}

// Build Data Source Factory using DefaultBandwidthMeter and HttpDataSource.Factory
private DataSource.Factory buildDataSourceFactory(DefaultBandwidthMeter bandwidthMeter){
    return new DefaultDataSourceFactory(this, bandwidthMeter, buildHttpDataSourceFactory(bandwidthMeter));
}

// Build Http Data Source Factory using DefaultBandwidthMeter
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter){
    return new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter);
}

// Activity onStop, player must be release because of memory saving
@Override
public void onStop(){
    super.onStop();
    player.release();
}

In activity xml file just use below,

<com.google.android.exoplayer2.ui.SimpleExoPlayerView android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I'm first at ExoPlayer Development, so this code may be strange

Even so, example code run without problems

@ojw28 ojw28 closed this Dec 18, 2016

@gh-darvishani

This comment has been minimized.

Copy link

commented Feb 28, 2017

mmmm are you sure this code work fine !!!!
are you test mp4 or other format
in my issue #2505 i use similar code but when i want to play mp4 format i just see a black page
can you help me !?

@lioun1729

This comment has been minimized.

Copy link
Author

commented Mar 24, 2017

@masiha68
This example is only for one dash stream
So, you must modify this code if you want to use the other format

@AGohil29

This comment has been minimized.

Copy link

commented Apr 21, 2017

@lioun1729
How can we play mp4 videos with exoplayer? Can you please help

@lioun1729

This comment has been minimized.

Copy link
Author

commented Apr 22, 2017

@AGohil29
I have no more experience about developing exoplayer app now

But I think that change class or object using by videoSource variable to play only mp4 data

Or you can see how to play and configure various video format data on exoplayer in demo app uploaded ExoPlayer github site

@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.
Projects
None yet
4 participants
You can’t perform that action at this time.