问题
I am trying the play the video by the exo Player, but it gives me this error:-
E/ExoPlayerImplInternal: Source error.
InvalidResponseCodeException: Response code: 404
This is my Activity Class :-
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?
回答1:
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);
}`
来源:https://stackoverflow.com/questions/45795420/e-exoplayerimplinternal-source-error-com-google-android-exoplayer2-upstream-htt