Exoplayer 基本使用的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Y1258429182/article/details/79441170

废话不多说,一步步实现播放再说

按照官网添加

打开 Exoplayer官网,添加需要的依赖。

public class MainActivity extends AppCompatActivity {

    private PlayerView mPlayerView;
    private SimpleExoPlayer mPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initExo();
    }

    private void initExo() {
        BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();

        TrackSelection.Factory videoTrackSelectionFactory =
                new AdaptiveTrackSelection.Factory(bandwidthMeter);
        TrackSelector trackSelector =
                new DefaultTrackSelector(videoTrackSelectionFactory);

        mPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
        //组件绑定播放器
        mPlayerView.setPlayer(mPlayer);

        DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter();
        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
                Util.getUserAgent(this, "yzplayer"), defaultBandwidthMeter);
        MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
                .createMediaSource(Uri.parse(Constants.URL));
        //开始播放
        mPlayer.prepare(videoSource);

    }

    private void initView() {
        mPlayerView = (PlayerView) findViewById(R.id.simple_exo);
    }
}

捷径

如果直接向看代码的出门右转过两个路口在左转,就是下边的连接,嗯,就是这样

Exoplayer 的基本使用

猜你喜欢

转载自blog.csdn.net/Y1258429182/article/details/79441170