Exo player DASH Streaming example
Asked Answered
C

3

17

I'm trying to play DASH video on android devices with the ExoPlayer from Google (http://developer.android.com/guide/topics/media/exoplayer.html). The documentation is very, very poor and I cannot find some simplest working example with DASH (if someone did it). In the video (https://www.youtube.com/watch?v=6VjF638VObA#t=462) it looks simple but in reality there is a lot of unknown objects. I want to use only ExoPlayer library and without using their github demo because it is very complex and I didn't find a way to add my testing URL because all samples are from YouTube.

Thanks

Calmative answered 7/2, 2015 at 19:46 Comment(2)
Ha ha.. Exactly.. Document is poor. Lot of features available but not documented all thingsRoid
is the exoplayer adaptive by itself? or do we need to write extra code?Stroll
H
13

Here is a simple dash playing example which will play your stream content into SimpleExoPlayerView from exoplayer-ui.

Add SimpleExoPlayerView to your layout and use the code below

    SimpleExoPlayerView exoPlayerView = (SimpleExoPlayerView) findViewById(R.id.exo_player_view);

    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "ExoPlayer"));
    Uri uri = Uri.parse("http://your_host/dash/stream.mpd");
    DashMediaSource dashMediaSource = new DashMediaSource(uri, dataSourceFactory,
            new DefaultDashChunkSource.Factory(dataSourceFactory), null, null);

    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));

    SimpleExoPlayer simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);

    exoPlayerView.setPlayer(simpleExoPlayer);
    simpleExoPlayer.prepare(dashMediaSource);

Also add the dependencies to your build.gradle

compile 'com.google.android.exoplayer:exoplayer-core:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-dash:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-hls:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-smoothstreaming:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-ui:r2.4.0'
Hydrosol answered 28/4, 2017 at 10:50 Comment(4)
The usage of Dash MediaSource in ExoPlayer is written right, but I think you don't need to add all the dependencies in the gradle as it will include all the sources. These Individual dependencies were released to be used by user by his or her requirement. including the following will suffice compile 'com.google.android.exoplayer:exoplayer-core:r2.4.0' compile 'com.google.android.exoplayer:exoplayer-dash:r2.4.0' compile 'com.google.android.exoplayer:exoplayer-ui:r2.4.0'Renascent
@BawenderYandra I have something here #48921178 please check. I am new to thisOzonize
@Hydrosol can you send another ocde for 2.9.4 ?Improbity
I tried your solution but am getting the following error ~> Source error.com.google.android.exoplayer2.ParserException: org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT ������ ftypisom������...@3:25 in java.io.InputStreamReader@8bd3c66)Nitza
Z
1

You should use new version:

implementation 'com.google.android.exoplayer:exoplayer:2.18.0'

exoPlayer = ExoPlayer.Builder(this).build()
exoPlayer?.playWhenReady = true
binding.playerView.player = exoPlayer
val defaultHttpDataSourceFactory = DefaultHttpDataSource.Factory()
val mediaItem = MediaItem.fromUri(URL)
val mediaSource = DashMediaSource.Factory(defaultHttpDataSourceFactory).createMediaSource(mediaItem)
exoPlayer?.setMediaSource(mediaSource)
exoPlayer?.seekTo(playbackPosition)
exoPlayer?.playWhenReady = playWhenReady
exoPlayer?.prepare()
Zach answered 12/7, 2022 at 18:8 Comment(0)
S
-2

Actually, it is quite simple to add your testing URL to the ExoPlayer demo application available in Github.

I've tried to explain the exact steps here https://mcmap.net/q/746286/-is-there-a-non-youtube-example-to-implement-dash-using-exoplayer

Squabble answered 21/4, 2015 at 5:10 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.