Exoplayer 播放 m3u8 时没有声音

时间:2021-03-23 05:07:39

标签: android streaming exoplayer

我目前正在做一个流媒体应用,但我遇到了 exployer 的问题,我的一些视频链接可以正常播放,但有些不是,这是我拥有的示例流媒体链接

http://202.57.43.60:8443/live/5748aabe4c9d661afbd7f4068248f664/99.m3u8

这是我的代码:

BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    LoadControl loadControl = new DefaultLoadControl();
    playerView  = findViewById(R.id.movie_exo_player);
    simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
    simpleExoPlayer.setAudioAttributes(new AudioAttributes
            .Builder().build());
    playerView.setPlayer(simpleExoPlayer);
    DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter();
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
            Util.getUserAgent(this, "Exo2"), defaultBandwidthMeter);
    DefaultHlsExtractorFactory defaultHlsExtractorFactory = new DefaultHlsExtractorFactory(FLAG_ALLOW_NON_IDR_KEYFRAMES);
    MediaSource mediaSource = new HlsMediaSource.Factory(dataSourceFactory)
                    .setExtractorFactory(defaultHlsExtractorFactory)
                    .createMediaSource(Uri.parse(VIDEO_TEST_URL));

    LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource);
    simpleExoPlayer.prepare(loopingSource);
    if(VIDEO_TEST_URL != null){
        simpleExoPlayer.prepare(mediaSource);
        simpleExoPlayer.setPlayWhenReady(true);
    }

非常感谢任何形式的帮助

0 个答案:

没有答案