Home > Mobile >  Exoplayer2 track switch MappedTrackInfo. GetTrackGroups (int) & # x27; On a null object reference
Exoplayer2 track switch MappedTrackInfo. GetTrackGroups (int) & # x27; On a null object reference

Time:04-01

 
Private void initializePlayer () {
TrackSelector=new DefaultTrackSelector ();
MappingTrackSelector. MappedTrackInfo trackInfo=trackSelector. GetCurrentMappedTrackInfo ();
If (trackInfo==null)
return;

DefaultTrackSelector. The Parameters. The Parameters=trackSelector getParameters () buildUpon ()
SetSelectionOverride (1, trackInfo getTrackGroups (1),
New DefaultTrackSelector. SelectionOverride (1, 1))
.build();
TrackSelector. SetParameters (parameters);

Player=ExoPlayerFactory. NewSimpleInstance (this, trackSelector);
PlayerView. SetPlayer (player);
Player. SetPlayWhenReady (true);
Player. SeekTo (currentWindow playbackPosition);
The DataSource. Factory dataSourceFactory=new DefaultDataSourceFactory (this,
Util. GetUserAgent (this, "ExoPlayer"));
Uri Uri=Uri. Parse (Environment. External.getexternalstoragedirectory () + "/Movies/3 dall. Mp4");
MediaSource videoSource=new ExtractorMediaSource. Factory (dataSourceFactory)
CreateMediaSource (uri);
Player. Prepare (videoSource);
}

For the first time to use ExoPlayer
Implementation of video language switch, trackInfo has always been a null
New DefaultTrackSelector. SelectionOverride (int groupIndex, int... The parameter hasn't been seen) figure out what
The first is the index of language? The second is what

CodePudding user response:

You don't need to set up here so much
 
TrackSelector=new DefaultTrackSelector ();
Player=ExoPlayerFactory. NewSimpleInstance (this, trackSelector);

In this way
  • Related