use of com.google.android.exoplayer2.trackselection.TrackSelector in project NewPipe by TeamNewPipe.
the class BasePlayer method initPlayer.
public void initPlayer() {
if (DEBUG)
Log.d(TAG, "initPlayer() called with: context = [" + context + "]");
if (databaseUpdateReactor != null)
databaseUpdateReactor.dispose();
databaseUpdateReactor = new CompositeDisposable();
final String userAgent = Downloader.USER_AGENT;
final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
dataSource = new PlayerDataSource(context, userAgent, bandwidthMeter);
final AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
trackSelector = new CustomTrackSelector(trackSelectionFactory);
final LoadControl loadControl = new LoadController(context);
final RenderersFactory renderFactory = new DefaultRenderersFactory(context);
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(renderFactory, trackSelector, loadControl);
simpleExoPlayer.addListener(this);
simpleExoPlayer.setPlayWhenReady(true);
simpleExoPlayer.setSeekParameters(PlayerHelper.getSeekParameters(context));
audioReactor = new AudioReactor(context, simpleExoPlayer);
mediaSessionManager = new MediaSessionManager(context, simpleExoPlayer, new BasePlayerMediaSession(this));
}
use of com.google.android.exoplayer2.trackselection.TrackSelector in project NewPipe by TeamNewPipe.
the class VideoPlayer method onTextTrackUpdate.
/*//////////////////////////////////////////////////////////////////////////
// ExoPlayer Track Updates
//////////////////////////////////////////////////////////////////////////*/
private void onTextTrackUpdate() {
final int textRenderer = getRendererIndex(C.TRACK_TYPE_TEXT);
if (captionTextView == null)
return;
if (trackSelector == null || trackSelector.getCurrentMappedTrackInfo() == null || textRenderer == RENDERER_UNAVAILABLE) {
captionTextView.setVisibility(View.GONE);
return;
}
final TrackGroupArray textTracks = trackSelector.getCurrentMappedTrackInfo().getTrackGroups(textRenderer);
// Extract all loaded languages
List<String> availableLanguages = new ArrayList<>(textTracks.length);
for (int i = 0; i < textTracks.length; i++) {
final TrackGroup textTrack = textTracks.get(i);
if (textTrack.length > 0 && textTrack.getFormat(0) != null) {
availableLanguages.add(textTrack.getFormat(0).language);
}
}
// Normalize mismatching language strings
final String preferredLanguage = trackSelector.getPreferredTextLanguage();
// Build UI
buildCaptionMenu(availableLanguages);
if (trackSelector.getRendererDisabled(textRenderer) || preferredLanguage == null || !availableLanguages.contains(preferredLanguage)) {
captionTextView.setText(R.string.caption_none);
} else {
captionTextView.setText(preferredLanguage);
}
captionTextView.setVisibility(availableLanguages.isEmpty() ? View.GONE : View.VISIBLE);
}
use of com.google.android.exoplayer2.trackselection.TrackSelector in project android by owncloud.
the class PreviewVideoActivity method preparePlayer.
// Video player internal methods
private void preparePlayer() {
// Create a default TrackSelector
AdaptiveTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
player = new SimpleExoPlayer.Builder(this).setTrackSelector(trackSelector).setLoadControl(new DefaultLoadControl()).build();
player.addListener(this);
exoPlayerView.setPlayer(player);
// Prepare video player asynchronously
new PrepareVideoPlayerAsyncTask(getApplicationContext(), this, getFile(), getAccount()).execute();
}
use of com.google.android.exoplayer2.trackselection.TrackSelector in project android by owncloud.
the class PreviewVideoFragment method preparePlayer.
// Video player internal methods
private void preparePlayer() {
AdaptiveTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
// Video streaming is only supported at Jelly Bean or higher Android versions (>= API 16)
// Create the player
player = new SimpleExoPlayer.Builder(requireContext()).setTrackSelector(trackSelector).setLoadControl(new DefaultLoadControl()).build();
player.addListener(this);
// Bind the player to the view.
exoPlayerView.setPlayer(player);
// Prepare video player asynchronously
new PrepareVideoPlayerAsyncTask(getActivity(), this, getFile(), mAccount).execute();
}
use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.
the class PlayerActivity method initializePlayer.
/**
* @return Whether initialization was successful.
*/
protected boolean initializePlayer() {
if (player == null) {
Intent intent = getIntent();
mediaItems = createMediaItems(intent);
if (mediaItems.isEmpty()) {
return false;
}
boolean preferExtensionDecoders = intent.getBooleanExtra(IntentUtil.PREFER_EXTENSION_DECODERS_EXTRA, false);
RenderersFactory renderersFactory = DemoUtil.buildRenderersFactory(/* context= */
this, preferExtensionDecoders);
trackSelector = new DefaultTrackSelector(/* context= */
this);
lastSeenTracksInfo = TracksInfo.EMPTY;
player = new ExoPlayer.Builder(/* context= */
this).setRenderersFactory(renderersFactory).setMediaSourceFactory(createMediaSourceFactory()).setTrackSelector(trackSelector).build();
player.setTrackSelectionParameters(trackSelectionParameters);
player.addListener(new PlayerEventListener());
player.addAnalyticsListener(new EventLogger(trackSelector));
player.setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */
true);
player.setPlayWhenReady(startAutoPlay);
playerView.setPlayer(player);
serverSideAdsLoader.setPlayer(player);
debugViewHelper = new DebugTextViewHelper(player, debugTextView);
debugViewHelper.start();
}
boolean haveStartPosition = startItemIndex != C.INDEX_UNSET;
if (haveStartPosition) {
player.seekTo(startItemIndex, startPosition);
}
player.setMediaItems(mediaItems, /* resetPosition= */
!haveStartPosition);
player.prepare();
updateButtonVisibility();
return true;
}
Aggregations