E/ExoPlayerImplInternal:源错误com.google.android.exoplayer2.upstream.HttpDataSource $ InvalidResponseCodeException:响应代码:404 [英] E/ExoPlayerImplInternal: Source error com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 404
本文介绍了E/ExoPlayerImplInternal:源错误com.google.android.exoplayer2.upstream.HttpDataSource $ InvalidResponseCodeException:响应代码:404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过exo Player播放视频,但这给了我这个错误:-
I am trying the play the video by the exo Player, but it gives me this error:-
E/ExoPlayerImplInternal:源错误.
InvalidResponseCodeException:响应代码:404
E/ExoPlayerImplInternal: Source error.
InvalidResponseCodeException: Response code: 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);
}
有人知道这是怎么回事吗?
Does anyone know what is wrong here?
推荐答案
您必须为链接使用最终"修饰符.
You must use the "final" modifier for your link.
`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);
}`
这篇关于E/ExoPlayerImplInternal:源错误com.google.android.exoplayer2.upstream.HttpDataSource $ InvalidResponseCodeException:响应代码:404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文