java E/外部播放器实施内部:源错误,返回上一个页面时发生错误,响应代码:404

8e2ybdfx  于 2022-10-30  发布在  Java
关注(0)|答案(1)|浏览(84)

我正在尝试播放视频的exo播放器,但它给我这个错误:-
E/外部播放器实施内部:来源错误。
无效响应代码异常:响应代码:404
这是我的活动类:-

public class VideoActivity extends AppCompatActivity implements VideoRendererEventListener {
    private String mVideoUrl;
    private SimpleExoPlayerView simpleExoPlayerView;
    private SimpleExoPlayer player;
    private static final String TAG = "AMAN";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);

    if (getIntent() != null)
        mVideoUrl = getIntent().getStringExtra("VideoUrl");

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

    LoadControl loadControl = new DefaultLoadControl();

    player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
    simpleExoPlayerView = new SimpleExoPlayerView(this);
    simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view);

    simpleExoPlayerView.setUseController(true);
    simpleExoPlayerView.requestFocus();

    simpleExoPlayerView.setPlayer(player);

    Uri mp4VideoUri =Uri.parse(mVideoUrl);

    DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter();

    DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), bandwidthMeterA);

    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();

    MediaSource videoSource = new HlsMediaSource(mp4VideoUri, dataSourceFactory, 1, null, null);
    final LoopingMediaSource loopingSource = new LoopingMediaSource(videoSource);

   player.prepare(loopingSource);
                    player.setPlayWhenReady(true);

}

有人知道这里出了什么问题吗?

krcsximq

krcsximq1#

您必须为链接使用“final”修饰符。

`protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    final String VIDEO_URL = getIntent().getExtras().getString("URL");

    playerView = findViewById(R.id.exo_player);
    simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this);
    playerView.setPlayer(simpleExoPlayer);
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
            Util.getUserAgent(this, "appname"));
    MediaSource videoSource  = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(VIDEO_URL));
    simpleExoPlayer.prepare(videoSource);
    simpleExoPlayer.setPlayWhenReady(true);
}`

相关问题