Java Code Examples for com.google.android.exoplayer2.trackselection.TrackSelection#Factory
The following examples show how to use
com.google.android.exoplayer2.trackselection.TrackSelection#Factory .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoActivity.java From arcusandroid with Apache License 2.0 | 7 votes |
private void initializePlayer() { CameraPreviewGetter.instance().pauseUpdates(); PlayerView video = findViewById(R.id.video_view); video.setUseController(playbackModel.getType() == PlaybackModel.PlaybackType.CLIP); video.requestFocus(); TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(DEFAULT_BANDWIDTH_METER); player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(this), new DefaultTrackSelector(trackSelectionFactory), new DefaultLoadControl() ); video.setPlayer(player); String userAgent = Util.getUserAgent(this, getPackageName()); DataSource.Factory dsf = new DefaultDataSourceFactory(this, userAgent); MediaSource mediaSource = new HlsMediaSource.Factory(dsf).createMediaSource(Uri.parse(playbackModel.getUrl())); player.prepare(mediaSource); player.addListener(eventListener); player.setPlayWhenReady(playWhenReady); player.seekTo(currentWindow, playbackPosition); }
Example 2
Source File: CompositeTrackSelectorCreator.java From no-player with Apache License 2.0 | 6 votes |
CompositeTrackSelector create(Options options, DefaultBandwidthMeter bandwidthMeter) { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory( bandwidthMeter, options.minDurationBeforeQualityIncreaseInMillis(), AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS, AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS, AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION, AdaptiveTrackSelection.DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE, AdaptiveTrackSelection.DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS, Clock.DEFAULT ); DefaultTrackSelector trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); DefaultTrackSelector.Parameters trackSelectorParameters = trackSelector.buildUponParameters() .setMaxVideoBitrate(options.maxVideoBitrate()) .build(); trackSelector.setParameters(trackSelectorParameters); ExoPlayerTrackSelector exoPlayerTrackSelector = ExoPlayerTrackSelector.newInstance(trackSelector); ExoPlayerAudioTrackSelector audioTrackSelector = new ExoPlayerAudioTrackSelector(exoPlayerTrackSelector); ExoPlayerVideoTrackSelector videoTrackSelector = new ExoPlayerVideoTrackSelector(exoPlayerTrackSelector); ExoPlayerSubtitleTrackSelector subtitleTrackSelector = new ExoPlayerSubtitleTrackSelector(exoPlayerTrackSelector); return new CompositeTrackSelector(trackSelector, audioTrackSelector, videoTrackSelector, subtitleTrackSelector); }
Example 3
Source File: VideoPlayer.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
private void setExoViewSource(@NonNull VideoSlide videoSource, boolean autoplay) throws IOException { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); exoPlayer.addListener(new ExoPlayerListener(window)); //noinspection ConstantConditions exoView.setPlayer(exoPlayer); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null); AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), defaultDataSourceFactory, null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null); exoPlayer.prepare(mediaSource); exoPlayer.setPlayWhenReady(autoplay); }
Example 4
Source File: PlaybackFragment.java From tv-samples with Apache License 2.0 | 6 votes |
private void initializePlayer() { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), mTrackSelector); mPlayerAdapter = new LeanbackPlayerAdapter(getActivity(), mPlayer, UPDATE_DELAY); mPlaylistActionListener = new PlaylistActionListener(mPlaylist); mPlayerGlue = new VideoPlayerGlue(getActivity(), mPlayerAdapter, mPlaylistActionListener); mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this)); mPlayerGlue.playWhenPrepared(); play(mVideo); ArrayObjectAdapter mRowsAdapter = initializeRelatedVideosRow(); setAdapter(mRowsAdapter); }
Example 5
Source File: PlaybackFragment.java From androidtv-Leanback with Apache License 2.0 | 6 votes |
private void initializePlayer() { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), mTrackSelector); mPlayerAdapter = new LeanbackPlayerAdapter(getActivity(), mPlayer, UPDATE_DELAY); mPlaylistActionListener = new PlaylistActionListener(mPlaylist); mPlayerGlue = new VideoPlayerGlue(getActivity(), mPlayerAdapter, mPlaylistActionListener); mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this)); mPlayerGlue.playWhenPrepared(); play(mVideo); ArrayObjectAdapter mRowsAdapter = initializeRelatedVideosRow(); setAdapter(mRowsAdapter); }
Example 6
Source File: YouTubePlayerV2Fragment.java From SkyTube with GNU General Public License v3.0 | 5 votes |
private SimpleExoPlayer createExoPlayer() { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); Context context = getContext(); DefaultRenderersFactory defaultRenderersFactory = new DefaultRenderersFactory(context); return ExoPlayerFactory.newSimpleInstance(getContext(), defaultRenderersFactory, trackSelector, new DefaultLoadControl(), null, bandwidthMeter); }
Example 7
Source File: VideoPlayer.java From Telegram with GNU General Public License v2.0 | 5 votes |
public VideoPlayer() { mediaDataSourceFactory = new ExtendedDefaultDataSourceFactory(ApplicationLoader.applicationContext, BANDWIDTH_METER, new DefaultHttpDataSourceFactory("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)", BANDWIDTH_METER)); mainHandler = new Handler(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); lastReportedPlaybackState = ExoPlayer.STATE_IDLE; NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.playerDidStartPlaying); }
Example 8
Source File: VideoPlayer.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public VideoPlayer() { mediaDataSourceFactory = new ExtendedDefaultDataSourceFactory(ApplicationLoader.applicationContext, BANDWIDTH_METER, new DefaultHttpDataSourceFactory("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)", BANDWIDTH_METER)); mainHandler = new Handler(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); lastReportedPlaybackState = ExoPlayer.STATE_IDLE; NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.playerDidStartPlaying); }
Example 9
Source File: StoryAudioPlayer.java From zom-android-matrix with Apache License 2.0 | 5 votes |
private SimpleExoPlayer getOrCreatePlayer() { if (player == null) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); concatenatingMediaSource = new ConcatenatingMediaSource(); player.prepare(concatenatingMediaSource); } return player; }
Example 10
Source File: VideoViewActivity.java From zom-android-matrix with Apache License 2.0 | 5 votes |
private void initializePlayer() { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); //test TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create the player mExoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector); ////Set media controller mPlayerView.setUseController(true);//set to true or false to see controllers mPlayerView.requestFocus(); // Bind the player to the view. mPlayerView.setPlayer(mExoPlayer); DataSpec dataSpec = new DataSpec(mMediaUri); final InputStreamDataSource inputStreamDataSource = new InputStreamDataSource(this, dataSpec); try { inputStreamDataSource.open(dataSpec); } catch (IOException e) { e.printStackTrace(); } DataSource.Factory factory = new DataSource.Factory() { @Override public DataSource createDataSource() { return inputStreamDataSource; } }; MediaSource audioSource = new ExtractorMediaSource(inputStreamDataSource.getUri(), factory, new DefaultExtractorsFactory(), null, null); mExoPlayer.prepare(audioSource); mExoPlayer.setPlayWhenReady(true); //run file/link when ready to play. }
Example 11
Source File: TrackSelectorWrapperTest.java From zapp with MIT License | 4 votes |
@Before public void setup() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); trackSelectorWrapper = new TrackSelectorWrapper(trackSelector); }
Example 12
Source File: MainActivity.java From WhatsAppStatusSaver with Apache License 2.0 | 4 votes |
public void showImagePopup(Point p, final String uri) { Activity context = MainActivity.this; //COMPLETED solving video problem final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.image_popup_layout); dialog.show(); WindowManager.LayoutParams lp = new WindowManager.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.copyFrom(dialog.getWindow().getAttributes()); dialog.getWindow().setAttributes(lp); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.getWindow().setDimAmount(0); // Getting a reference to Close button, and close the popup when clicked. FloatingActionButton close = (FloatingActionButton) dialog.findViewById(R.id.close_image_popup_button); ImageView statusImage = (ImageView) dialog.findViewById(R.id.full_status_image_view); final SimpleExoPlayerView simpleExoPlayerView = dialog.findViewById(R.id.full_status_video_view); final SimpleExoPlayer player; if (uri.endsWith(".jpg")) { GlideApp.with(context).load(uri).into(statusImage); } else if (uri.endsWith(".mp4")) { statusImage.setVisibility(View.GONE); simpleExoPlayerView.setVisibility(View.VISIBLE); Uri myUri = Uri.parse(uri); // initialize Uri here // 1. Create a default TrackSelector BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create a default LoadControl LoadControl loadControl = new DefaultLoadControl(); // 3. Create the player player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); //Set media controller simpleExoPlayerView.setUseController(true); simpleExoPlayerView.requestFocus(); // Bind the player to the view. simpleExoPlayerView.setPlayer(player); //Measures bandwidth during playback. Can be null if not required. DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter(); //Produces DataSource instances through which media data is loaded. DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util. getUserAgent(this, "exoplayer2example"), bandwidthMeterA); //Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource videoSource = new ExtractorMediaSource(myUri, dataSourceFactory, extractorsFactory, null, null); player.prepare(videoSource); player.setPlayWhenReady(true); //run file/link when ready to play. dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { player.release(); } }); } close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // popup.dismiss(); dialog.cancel(); } }); }
Example 13
Source File: TrackSelectionHelper.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
/** * @param selector The track selector. * @param adaptiveTrackSelectionFactory A factory for adaptive {@link TrackSelection}s, or null * if the selection helper should not support adaptive tracks. */ public TrackSelectionHelper(MappingTrackSelector selector, TrackSelection.Factory adaptiveTrackSelectionFactory) { this.selector = selector; this.adaptiveTrackSelectionFactory = adaptiveTrackSelectionFactory; }
Example 14
Source File: VideoActivity.java From evercam-android with GNU Affero General Public License v3.0 | 4 votes |
private void preparePlayer() { if (player == null){ DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null; @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode = ((EvercamPlayApplication) getApplication()).useExtensionRenderers() ? (false ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON) : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF; TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl(), drmSessionManager, extensionRendererMode); player.addListener(this); eventLogger = new EventLogger(trackSelector); eventLogger.addListener(this); player.addListener(eventLogger); // player.setAudioDebugListener(eventLogger); player.setVideoDebugListener(eventLogger); player.setMetadataOutput(eventLogger); Uri hlsUrl = Uri.parse(evercamCamera.getHlsUrl()); MediaSource mediaSource = new HlsMediaSource(hlsUrl, mediaDataSourceFactory, mainHandler, eventLogger); boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; if (haveResumePosition) { player.seekTo(resumeWindow, resumePosition); } player.prepare(mediaSource, !haveResumePosition, false); player.setPlayWhenReady(true); player.setVideoSurface(surface); }else{ releasePlayer(); preparePlayer(); } /*DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null; @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode = ((EvercamPlayApplication) getApplication()).useExtensionRenderers() ? (false ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON) : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF; TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl(), drmSessionManager, extensionRendererMode); player.addListener(this); eventLogger = new EventLogger(trackSelector); eventLogger.addListener(this); player.addListener(eventLogger); // player.setAudioDebugListener(eventLogger); player.setVideoDebugListener(eventLogger); player.setMetadataOutput(eventLogger); Uri hlsUrl = Uri.parse(evercamCamera.getHlsUrl()); MediaSource mediaSource = new HlsMediaSource(hlsUrl, mediaDataSourceFactory, mainHandler, eventLogger); player.prepare(mediaSource); player.setPlayWhenReady(true); player.setVideoSurface(surface);*/ }
Example 15
Source File: PlayerActivity.java From leafpicrevived with GNU General Public License v3.0 | 4 votes |
/** * Internal methods */ private void initializePlayer() { Intent intent = getIntent(); boolean needNewPlayer = player == null; if (needNewPlayer) { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); trackSelectionHelper = new TrackSelectionHelper(trackSelector, adaptiveTrackSelectionFactory, getThemeHelper()); lastSeenTrackGroupArray = null; UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA) ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null; DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null; if (drmSchemeUuid != null) { String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL); String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES); boolean multiSession = intent.getBooleanExtra(DRM_MULTI_SESSION, false); int errorStringId = R.string.error_drm_unknown; try { drmSessionManager = buildDrmSessionManagerV18(drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray, multiSession); } catch (UnsupportedDrmException e) { errorStringId = e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown; } if (drmSessionManager == null) { showToast(errorStringId); return; } } DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER); player = ExoPlayerFactory.newSimpleInstance(this.context, trackSelector); player.addListener(new PlayerEventListener()); simpleExoPlayerView.setPlayer(player); player.setPlayWhenReady(shouldAutoPlay); if (Prefs.getLoopVideo()) { player.setRepeatMode(Player.REPEAT_MODE_ALL); } else { player.setRepeatMode(Player.REPEAT_MODE_OFF); } } String action = intent.getAction(); Uri[] uris; String[] extensions; if (intent.getData() != null && intent.getType() != null) { uris = new Uri[]{intent.getData()}; extensions = new String[]{intent.getType()}; } else { // TODO: 12/7/16 asdasd showToast(getString(R.string.unexpected_intent_action, action)); return; } MediaSource[] mediaSources = new MediaSource[uris.length]; for (int i = 0; i < uris.length; i++) { mediaSources[i] = buildMediaSource(uris[i], extensions[i]); } MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources); boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; if (haveResumePosition) { player.seekTo(resumeWindow, resumePosition); } player.prepare(mediaSource, !haveResumePosition, false); inErrorState = false; supportInvalidateOptionsMenu(); }
Example 16
Source File: TrackSelectionHelper.java From leafpicrevived with GNU General Public License v3.0 | 4 votes |
private void setOverride(int group, int[] tracks, boolean enableRandomAdaptation) { TrackSelection.Factory factory = tracks.length == 1 ? FIXED_FACTORY : (enableRandomAdaptation ? RANDOM_FACTORY : adaptiveVideoTrackSelectionFactory); override = new SelectionOverride(group, tracks); }
Example 17
Source File: ImageActivity.java From cloudinary_android with MIT License | 4 votes |
private void initExoPlayer() { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector); exoPlayerView = ((SimpleExoPlayerView) findViewById(R.id.exoPlayer)); exoPlayerView.setPlayer(exoPlayer); listener = new ExoPlayer.EventListener() { @Override public void onTracksChanged(TrackGroupArray trackGroupArray, TrackSelectionArray trackSelectionArray) { if (trackGroupArray.length > 0) { progressBar.setVisibility(View.GONE); } } @Override public void onLoadingChanged(boolean b) { progressBar.setVisibility(b ? View.VISIBLE : View.GONE); } @Override public void onPlayerStateChanged(boolean b, int i) { } @Override public void onPlayerError(ExoPlaybackException e) { progressBar.setVisibility(View.GONE); Toast.makeText(ImageActivity.this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show(); } @Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { } }; }
Example 18
Source File: TrackSelectionHelper.java From ExoPlayer-Offline with Apache License 2.0 | 4 votes |
/** * @param selector The track selector. * @param adaptiveVideoTrackSelectionFactory A factory for adaptive video {@link TrackSelection}s, * or null if the selection helper should not support adaptive video. */ public TrackSelectionHelper(MappingTrackSelector selector, TrackSelection.Factory adaptiveVideoTrackSelectionFactory) { this.selector = selector; this.adaptiveVideoTrackSelectionFactory = adaptiveVideoTrackSelectionFactory; }
Example 19
Source File: TrackSelectionHelper.java From leafpicrevived with GNU General Public License v3.0 | 4 votes |
/** * @param selector The track selector. * @param adaptiveVideoTrackSelectionFactory A factory for adaptive video {@link TrackSelection}s, * or null if the selection helper should not support adaptive video. */ public TrackSelectionHelper(MappingTrackSelector selector, TrackSelection.Factory adaptiveVideoTrackSelectionFactory, ThemeHelper themeHelper) { this.selector = selector; this.adaptiveVideoTrackSelectionFactory = adaptiveVideoTrackSelectionFactory; this.themeHelper = themeHelper; }
Example 20
Source File: VideoPlayer.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public void setVideoSource(@NonNull VideoSlide videoSource, boolean autoplay) { Context context = getContext(); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(context); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); exoPlayer = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector, loadControl); exoPlayer.addListener(new ExoPlayerListener(window, playerStateCallback)); exoPlayer.addListener(new Player.DefaultEventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playerCallback != null) { switch (playbackState) { case Player.STATE_READY: if (playWhenReady) playerCallback.onPlaying(); break; case Player.STATE_ENDED: playerCallback.onStopped(); break; } } } }); exoView.setPlayer(exoPlayer); exoControls.setPlayer(exoPlayer); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(context, "GenericUserAgent", null); AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(context, defaultDataSourceFactory, null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); createMediaSource = () -> new ExtractorMediaSource.Factory(attachmentDataSourceFactory) .setExtractorsFactory(extractorsFactory) .createMediaSource(videoSource.getUri()); exoPlayer.prepare(createMediaSource.create()); exoPlayer.setPlayWhenReady(autoplay); }