2015-02-07 115 views
11

我試圖在谷歌(http://developer.android.com/guide/topics/media/exoplayer.html)上使用ExoPlayer在Android設備上播放DASH視頻。該文檔非常非常差,我找不到DASH(如果有人這樣做)的一些最簡單的工作示例。在視頻(https://www.youtube.com/watch?v=6VjF638VObA#t=462)看起來很簡單,但實際上有很多未知的對象。我只想使用ExoPlayer庫,而不使用他們的github演示,因爲它非常複雜,我沒有找到添加我的測試網址的方法,因爲所有樣本都來自YouTube。Exo player DASH Streaming example

感謝

+0

哈哈..沒錯..文檔較差。很多功能可用,但沒有記錄所有東西 – 2017-10-03 03:58:14

回答

6

下面是一個簡單的破折號玩例如,將播放流內容到SimpleExoPlayerViewexoplayer-ui

添加SimpleExoPlayerView到您的佈局和使用以下

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); 

代碼還依賴添加到您的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' 
+0

在ExoPlayer中使用Dash MediaSource是正確的,但我認爲您不需要在gradle中添加所有依賴項,因爲它將包含所有源。這些個人依賴性被髮布以供用戶根據他或她的要求使用。包括以下內容就足夠了 compile'c​​om.google.android.exoplayer:exoplayer-core:r2.4.0' compile'c​​om.google.android.exoplayer:exoplayer-dash:r2.4.0' compile'c​​om.google .android.exoplayer:exoplayer-ui:r2.4.0' – 2018-02-02 04:08:57

+0

@BawenderYandra我在這裏有東西https://stackoverflow.com/questions/48920678/expoplayer-how-to-know-which-url-to-be-played-與定製視頻查看請檢查。我是新來的 – 2018-02-22 06:08:47