java ExoPlayer DASH Media无法在Samsung Galaxy Duos 4.1.2中播放

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java ExoPlayer DASH Media无法在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();
    }
}

以上是关于java ExoPlayer DASH Media无法在Samsung Galaxy Duos 4.1.2中播放的主要内容,如果未能解决你的问题,请参考以下文章

AndroidX Media3之ExoPlayer简单使用

Android Widevine DASH 实现 + ExoPlayer

android,Exoplayer实现视频播放器

音视频开发之旅(44)-ExoPlayer介绍及简单使用

如何使用media-server搭建DASH服务

androidexoplayer固定宽高大小