com.google.android.exoplayer2.ui.DebugTextViewHelper Java Examples

The following examples show how to use com.google.android.exoplayer2.ui.DebugTextViewHelper. 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: MediaPlayerFragment.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
private void initializePlayer() {
	Intent intent = fragActivity.getIntent();
	boolean needNewPlayer = player == null;
	if (needNewPlayer) {
		boolean preferExtensionDecoders = intent.getBooleanExtra(PREFER_EXTENSION_DECODERS, false);
		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);
			try {
				drmSessionManager = buildDrmSessionManager(drmSchemeUuid, drmLicenseUrl,
														   keyRequestPropertiesArray);
			} catch (UnsupportedDrmException e) {
				int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported
					: (e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME
					? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown);
				showToast(errorStringId);
				return;
			}
		}

		@SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode =
			((ExplorerApplication) fragActivity.getApplication()).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);
		trackSelectionHelper = new TrackSelectionHelper(trackSelector, videoTrackSelectionFactory);
		player = ExoPlayerFactory.newSimpleInstance(fragActivity, trackSelector, new DefaultLoadControl(),
													drmSessionManager, 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;
		if (Intent.ACTION_VIEW.equals(action)) {
			uris = new Uri[] {intent.getData()};
			extensions = new String[] {intent.getStringExtra(EXTENSION_EXTRA)};
		} else if (ACTION_VIEW.equals(action)) {
			uris = new Uri[] {intent.getData()};
			extensions = new String[] {intent.getStringExtra(EXTENSION_EXTRA)};
		} else if (ACTION_VIEW_LIST.equals(action)) {
			String[] uriStrings = intent.getStringArrayExtra(URI_LIST_EXTRA);
			uris = new Uri[uriStrings.length];
			for (int i = 0; i < uriStrings.length; i++) {
				uris[i] = Uri.parse(uriStrings[i]);
			}
			extensions = intent.getStringArrayExtra(EXTENSION_LIST_EXTRA);
			if (extensions == null) {
				extensions = new String[uriStrings.length];
			}
		} else {
			if (!Intent.ACTION_MAIN.equals(action)) {
				showToast(getString(R.string.unexpected_intent_action, action));
			}
			return;
		}
		if (Util.maybeRequestReadExternalStoragePermission(fragActivity, 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;
		updateButtonVisibilities();
	}
}
 
Example #2
Source File: LiveVideoPlayerActivity.java    From LiveVideoBroadcaster with Apache License 2.0 4 votes vote down vote up
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;
  }
}