// Internal methods private void initializePlayer() { Intent intent = Intent; bool needNewPlayer = player == null; if (needNewPlayer) { var adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); trackSelectionHelper = new TrackSelectionHelper(trackSelector, adaptiveTrackSelectionFactory); lastSeenTrackGroupArray = null; eventLogger = new EventLogger(trackSelector); var drmSchemeUuid = intent.HasExtra(DRM_SCHEME_UUID_EXTRA) ? UUID.FromString(intent.GetStringExtra(DRM_SCHEME_UUID_EXTRA)) : null; IDrmSessionManager drmSessionManager = null; if (drmSchemeUuid != null) { var drmLicenseUrl = intent.GetStringExtra(DRM_LICENSE_URL); var keyRequestPropertiesArray = intent.GetStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES); int errorStringId = Resource.String.error_drm_unknown; if (Util.Util.SdkInt < 18) { errorStringId = Resource.String.error_drm_not_supported; } else { try { drmSessionManager = BuildDrmSessionManagerV18(drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray); } catch (UnsupportedDrmException e) { errorStringId = e.Reason == UnsupportedDrmException.ReasonUnsupportedScheme ? Resource.String.error_drm_unsupported_scheme : Resource.String.error_drm_unknown; } } if (drmSessionManager == null) { ShowToast(errorStringId); return; } } var preferExtensionDecoders = intent.GetBooleanExtra(PREFER_EXTENSION_DECODERS, false); var extensionRendererMode = ((DemoApplication)Application).UseExtensionRenderers() ? (preferExtensionDecoders ? DefaultRenderersFactory.ExtensionRendererModePrefer : DefaultRenderersFactory.ExtensionRendererModeOn) : DefaultRenderersFactory.ExtensionRendererModeOff; var renderersFactory = new DefaultRenderersFactory(this, drmSessionManager, extensionRendererMode); player = ExoPlayerFactory.NewSimpleInstance(renderersFactory, trackSelector); player.AddListener(this); player.AddListener(eventLogger); player.SetAudioDebugListener(eventLogger); player.SetVideoDebugListener(eventLogger); player.SetMetadataOutput(eventLogger); simpleExoPlayerView.Player = player; player.PlayWhenReady = shouldAutoPlay; debugViewHelper = new DebugTextViewHelper(player, debugTextView); debugViewHelper.Start(); } var action = intent.Action; Uri[] uris; string[] extensions; if (ACTION_VIEW.Equals(action)) { uris = new Uri[] { intent.Data }; extensions = new string[] { intent.GetStringExtra(EXTENSION_EXTRA) }; } else if (ACTION_VIEW_LIST.Equals(action)) { var 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 { ShowToast(GetString(Resource.String.unexpected_intent_action, action)); return; } if (Util.Util.MaybeRequestReadExternalStoragePermission(this, uris)) { // The player will be reinitialized if the permission is granted. return; } var mediaSources = new IMediaSource[uris.Length]; for (var i = 0; i < uris.Length; i++) { mediaSources[i] = BuildMediaSource(uris[i], extensions[i]); } var mediaSource = mediaSources.Length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources); var adTagUriString = intent.GetStringExtra(AD_TAG_URI_EXTRA); if (adTagUriString != null) { Uri adTagUri = Uri.Parse(adTagUriString); if (!adTagUri.Equals(loadedAdTagUri)) { ReleaseAdsLoader(); loadedAdTagUri = adTagUri; } try { mediaSource = CreateAdsMediaSource(mediaSource, Uri.Parse(adTagUriString)); } catch (System.Exception) { ShowToast(Resource.String.ima_not_loaded); } } else { ReleaseAdsLoader(); } bool haveResumePosition = resumeWindow != C.IndexUnset; if (haveResumePosition) { player.SeekTo(resumeWindow, resumePosition); } player.Prepare(mediaSource, !haveResumePosition, false); inErrorState = false; UpdateButtonVisibilities(); }