Java Code Examples for com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection#Factory
The following examples show how to use
com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection#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: 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 4
Source File: KExoMediaPlayer.java From K-Sonic with MIT License | 6 votes |
public KExoMediaPlayer(Context context) { this.context = context.getApplicationContext(); // =========@Init@========= TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this.context, trackSelector, new DefaultLoadControl(), null); player.addListener(eventLogger); player.addListener(playerListener); player.setVideoListener(playerListener); player.setPlayWhenReady(false); mainHandler = new Handler(); userAgent = Util.getUserAgent(this.context, "KExoMediaPlayer"); mediaDataSourceFactory = new DefaultDataSourceFactory(this.context, userAgent, BANDWIDTH_METER); }
Example 5
Source File: TubiPlayerActivity.java From TubiPlayer with MIT License | 6 votes |
protected void initMoviePlayer() { // 1. Create a default TrackSelector mMainHandler = new Handler(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 3. Create the mMoviePlayer mMoviePlayer = ExoPlayerFactory.newSimpleInstance(this, mTrackSelector); mEventLogger = new EventLogger(mTrackSelector); mMoviePlayer.addAnalyticsListener(mEventLogger); mMoviePlayer.addMetadataOutput(mEventLogger); mTubiPlayerView.setPlayer(mMoviePlayer, this); mTubiPlayerView.setMediaModel(mediaModel); }
Example 6
Source File: AndExoPlayerView.java From MagicalExoPlayer with MIT License | 6 votes |
private void initializePlayer() { if (simpleExoPlayer == null) { bandwidthMeter = new DefaultBandwidthMeter(); extractorsFactory = new DefaultExtractorsFactory(); trackSelectionFactory = new AdaptiveTrackSelection.Factory(); trackSelector = new DefaultTrackSelector(); simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector); playerView.setPlayer(simpleExoPlayer); simpleExoPlayer.setPlayWhenReady(currPlayWhenReady); simpleExoPlayer.seekTo(currentWindow, playbackPosition); simpleExoPlayer.addListener(componentListener); } }
Example 7
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 8
Source File: VideoExoPlayer.java From TigerVideo with Apache License 2.0 | 5 votes |
/**--------------------- 创建SimpleExoPlayer ----------------------------**/ private void initExoPlayer() { mMediaDataSourceFactory = buildDataSourceFactory(true); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mEventLogger = new EventLogger(mTrackSelector); mMainHandler = new Handler(Looper.getMainLooper()); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(mContext, null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); mExoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, mTrackSelector); mExoPlayer.addListener(mEventLogger); mExoPlayer.setAudioDebugListener(mEventLogger); mExoPlayer.setVideoDebugListener(mEventLogger); mExoPlayer.setMetadataOutput(mEventLogger); mExoPlayer.setTextOutput(null); mExoPlayer.setVideoListener(null); mExoPlayer.removeListener(this); mExoPlayer.setVideoTextureView(null); mExoPlayer.setVideoListener(this); mExoPlayer.addListener(this); mExoPlayer.setTextOutput(this); }
Example 9
Source File: ExoVideoView.java From ExoVideoView with Apache License 2.0 | 5 votes |
private void createExoPlayer(MediaSourceCreator creator) { if (player != null) { releasePlayer(); } DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext()); renderersFactory.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); SimpleExoPlayer.Builder builder = new SimpleExoPlayer.Builder(getContext(), renderersFactory); TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(getContext(),new AdaptiveTrackSelection.Factory()); builder.setTrackSelector(new DefaultTrackSelector(getContext(),adaptiveTrackSelectionFactory)); builder.setTrackSelector(trackSelector); builder.setBandwidthMeter(new DefaultBandwidthMeter.Builder(getContext()).build()); SimpleExoPlayer internalPlayer = builder.build(); internalPlayer.addListener(componentListener); internalPlayer.addListener(creator.getEventLogger()); internalPlayer.addMetadataOutput(creator.getEventLogger()); setPlayer(internalPlayer); }
Example 10
Source File: ProviderTvPlayer.java From xipl with Apache License 2.0 | 5 votes |
/** * Initializes and prepares the player but doesn't make it play the content. * * @param context the context needed to initialize the player. */ private void init(Context context) { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); player.prepare(getMediaSource(context)); }
Example 11
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 12
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 13
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 14
Source File: VideoPlayer.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public VideoPlayer(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); inflate(context, R.layout.video_player_layout, this); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); RenderersFactory renderersFactory = new DefaultRenderersFactory(getContext()); this.exoView = findViewById(R.id.video_view); this.exoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl); this.exoPlayer.addListener(new ExoPlayerListener()); if (exoView != null) { exoView.setPlayer(exoPlayer); } this.audioView = findViewById(R.id.audio_btn); this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); // VolumeChangeObserver.INSTANCE.registerReceiver(); // VolumeChangeObserver.INSTANCE.addCallback(observerCallback); audioVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); exoPlayer.setVolume(audioVolume); if (audioVolume == 0) { audioView.setImageResource(R.drawable.common_video_player_mute_icon); isMuted = true; } }
Example 15
Source File: Player.java From zapp with MIT License | 4 votes |
public Player(Context context) { settings = new SettingsRepository(context); networkConnectionHelper = new NetworkConnectionHelper(context); String userAgent = Util.getUserAgent(context, context.getString(R.string.app_name)); TransferListener transferListener = new OnlyWifiTransferListener(); dataSourceFactory = new DefaultDataSourceFactory(context, userAgent, transferListener); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); playerHandler = new Handler(player.getApplicationLooper()); trackSelectorWrapper = new TrackSelectorWrapper(trackSelector); // media session setup mediaSession = new MediaSessionCompat(context, context.getPackageName()); MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession); mediaSessionConnector.setPlayer(player, null); mediaSession.setActive(true); // audio focus setup AudioAttributes audioAttributes = new AudioAttributes.Builder() .setUsage(C.USAGE_MEDIA) .setContentType(C.CONTENT_TYPE_MOVIE) .build(); player.setAudioAttributes(audioAttributes, true); playerEventHandler = new PlayerEventHandler(); // enable subtitles enableSubtitles(settings.getEnableSubtitles()); // wakelocks playerWakeLocks = new PlayerWakeLocks(context, "Zapp::Player"); Disposable wakelockDisposable = playerEventHandler .getShouldHoldWakelock() .distinctUntilChanged() .subscribe(this::shouldHoldWakelockChanged); disposables.add(wakelockDisposable); // set listeners networkConnectionHelper.startListenForNetworkChanges(this::setStreamQualityByNetworkType); }
Example 16
Source File: DoubleViewTubiPlayerActivity.java From TubiPlayer with MIT License | 4 votes |
private void setupAdPlayer() { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER_AD); trackSelector_ad = new DefaultTrackSelector(adaptiveTrackSelectionFactory); adPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector_ad); }
Example 17
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 18
Source File: LiveVideoPlayerActivity.java From LiveVideoBroadcaster with Apache License 2.0 | 4 votes |
private void initializePlayer(String rtmpUrl) { Intent intent = getIntent(); boolean needNewPlayer = player == null; if (needNewPlayer) { boolean preferExtensionDecoders = intent.getBooleanExtra(PREFER_EXTENSION_DECODERS, false); @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode = useExtensionRenderers() ? (preferExtensionDecoders ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON) : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF; TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl(), null, extensionRendererMode); // player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, // new DefaultLoadControl(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE), 500, 1500, 500, 1500), // null, extensionRendererMode); player.addListener(this); eventLogger = new EventLogger(trackSelector); player.addListener(eventLogger); player.setAudioDebugListener(eventLogger); player.setVideoDebugListener(eventLogger); player.setMetadataOutput(eventLogger); simpleExoPlayerView.setPlayer(player); player.setPlayWhenReady(shouldAutoPlay); debugViewHelper = new DebugTextViewHelper(player, debugTextView); debugViewHelper.start(); } if (needNewPlayer || needRetrySource) { // String action = intent.getAction(); Uri[] uris; String[] extensions; uris = new Uri[1]; uris[0] = Uri.parse(rtmpUrl); extensions = new String[1]; extensions[0] = ""; if (Util.maybeRequestReadExternalStoragePermission(this, uris)) { // The player will be reinitialized if the permission is granted. 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); needRetrySource = false; } }
Example 19
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 20
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) { } }; }