示例#1
0
        protected override void OnTaskStateChanged(TaskState taskState)
        {
            if (taskState.Action.IsRemoveAction)
            {
                return;
            }
            Notification notification = null;

            byte[] bytes = new byte[taskState.Action.Data.Count];
            taskState.Action.Data.CopyTo(bytes, 0);

            if (taskState.State == TaskState.StateCompleted)
            {
                notification =
                    DownloadNotificationUtil.BuildDownloadCompletedNotification(
                        /* context= */ this,
                        Resource.Drawable.exo_controls_play,
                        CHANNEL_ID,
                        /* contentIntent= */ null,
                        Utils.FromUtf8Bytes(bytes));
            }
            else if (taskState.State == TaskState.StateFailed)
            {
                notification =
                    DownloadNotificationUtil.BuildDownloadFailedNotification(
                        /* context= */ this,
                        Resource.Drawable.exo_controls_play,
                        CHANNEL_ID,
                        /* contentIntent= */ null,
                        Utils.FromUtf8Bytes(bytes));
            }
            int notificationId = FOREGROUND_NOTIFICATION_ID + 1 + taskState.TaskId;

            NotificationUtil.SetNotification(this, notificationId, notification);
        }
            private SampleGroup getGroup(string groupName, List <SampleGroup> groups)
            {
                for (int i = 0; i < groups.Count; i++)
                {
                    if (Utils.AreEqual(groupName, groups[i].title))
                    {
                        return(groups[i]);
                    }
                }
                SampleGroup group = new SampleGroup(groupName);

                groups.Add(group);
                return(group);
            }
示例#3
0
        private IMediaSource BuildMediaSource(android.Net.Uri uri, string overrideExtension)
        {
            int type = Utils.InferContentType(uri, overrideExtension);

            IMediaSource src = null;

            switch (type)
            {
            case C.TypeDash:
                src = new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(mediaDataSourceFactory), BuildDataSourceFactory(false))
                      .SetManifestParser(new FilteringManifestParser(new DashManifestParser(), GetOfflineStreamKeys(uri)))
                      .CreateMediaSource(uri);
                break;

            case C.TypeSs:
                src = new SsMediaSource.Factory(new DefaultSsChunkSource.Factory(mediaDataSourceFactory), BuildDataSourceFactory(false))
                      .SetManifestParser(new FilteringManifestParser(new SsManifestParser(), GetOfflineStreamKeys(uri)))
                      .CreateMediaSource(uri);
                break;

            case C.TypeHls:
                src = new HlsMediaSource.Factory(mediaDataSourceFactory)
                      .SetPlaylistParserFactory(new FilteringManifestParser(new HlsPlaylistParser(), GetOfflineStreamKeys(uri)))
                      .CreateMediaSource(uri);
                break;

            case C.TypeOther:
                src = new ExtractorMediaSource.Factory(mediaDataSourceFactory).CreateMediaSource(uri);
                break;

            default:
                throw new IllegalStateException("Unsupported type: " + type);
            }

            //Todo: implement IAnalyticsListener
            src.AddEventListener(mainHandler, eventLogger);
            return(src);
        }
            protected override List <SampleGroup> RunInBackground(params string[] uris)
            {
                List <SampleGroup> result     = new List <SampleGroup>();
                Context            context    = activity.ApplicationContext;
                string             userAgent  = Utils.GetUserAgent(context, "ExoPlayerDemo");
                IDataSource        dataSource = new DefaultDataSource(context, null, userAgent, false);

                foreach (string uri in uris)
                {
                    DataSpec dataSpec    = new DataSpec(android.Net.Uri.Parse(uri));
                    var      inputStream = new DataSourceInputStream(dataSource, dataSpec);
                    var      memory      = new MemoryStream();
                    var      buffer      = new byte[1024];
                    int      read;
                    while ((read = inputStream.Read(buffer)) > 0)
                    {
                        memory.Write(buffer, 0, read);
                    }
                    memory.Seek(0, SeekOrigin.Begin);

                    try
                    {
                        ReadSampleGroups(new JsonReader(new InputStreamReader(memory, "UTF-8")), result);
                    }
                    catch (Exception e)
                    {
                        Log.Error(TAG, "Error loading sample list: " + uri, e);
                        sawError = true;
                    }
                    finally
                    {
                        Utils.CloseQuietly(dataSource);
                    }
                }

                return(result);
            }
示例#5
0
        // Internal methods

        private void InitializePlayer()
        {
            if (player == null)
            {
                Intent            intent = Intent;
                string            action = intent.Action;
                android.Net.Uri[] uris;
                string[]          extensions;

                if (ACTION_VIEW.Equals(action))
                {
                    uris       = new android.Net.Uri[] { intent.Data };
                    extensions = new string[] { intent.GetStringExtra(EXTENSION_EXTRA) };
                }
                else if (ACTION_VIEW_LIST.Equals(action))
                {
                    string[] uristrings = intent.GetStringArrayExtra(URI_LIST_EXTRA);
                    uris = new android.Net.Uri[uristrings.Length];
                    for (int i = 0; i < uristrings.Length; i++)
                    {
                        uris[i] = android.Net.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));
                    Finish();
                    return;
                }
                if (Utils.MaybeRequestReadExternalStoragePermission(this, uris))
                {
                    // The player will be reinitialized if the permission is granted.
                    return;
                }

                DefaultDrmSessionManager drmSessionManager = null;
                if (intent.HasExtra(DRM_SCHEME_EXTRA) || intent.HasExtra(DRM_SCHEME_UUID_EXTRA))
                {
                    string   drmLicenseUrl             = intent.GetStringExtra(DRM_LICENSE_URL_EXTRA);
                    string[] keyRequestPropertiesArray =
                        intent.GetStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES_EXTRA);
                    bool multiSession  = intent.GetBooleanExtra(DRM_MULTI_SESSION_EXTRA, false);
                    int  errorstringId = Resource.String.error_drm_unknown;
                    if (Utils.SdkInt < 18)
                    {
                        errorstringId = Resource.String.error_drm_not_supported;
                    }
                    else
                    {
                        try
                        {
                            string drmSchemeExtra = intent.HasExtra(DRM_SCHEME_EXTRA) ? DRM_SCHEME_EXTRA
                                : DRM_SCHEME_UUID_EXTRA;
                            UUID drmSchemeUuid = Utils.GetDrmUuid(intent.GetStringExtra(drmSchemeExtra));
                            if (drmSchemeUuid == null)
                            {
                                errorstringId = Resource.String.error_drm_unsupported_scheme;
                            }
                            else
                            {
                                drmSessionManager =
                                    BuildDrmSessionManagerV18(
                                        drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray, multiSession);
                            }
                        }
                        catch (UnsupportedDrmException e)
                        {
                            errorstringId = e.Reason == UnsupportedDrmException.ReasonUnsupportedScheme
                                ? Resource.String.error_drm_unsupported_scheme : Resource.String.error_drm_unknown;
                        }
                    }
                    if (drmSessionManager == null)
                    {
                        ShowToast(errorstringId);
                        Finish();
                        return;
                    }
                }

                ITrackSelectionFactory trackSelectionFactory;
                string abrAlgorithm = intent.GetStringExtra(ABR_ALGORITHM_EXTRA);
                if (abrAlgorithm == null || ABR_ALGORITHM_DEFAULT.Equals(abrAlgorithm))
                {
                    trackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
                }
                else if (ABR_ALGORITHM_RANDOM.Equals(abrAlgorithm))
                {
                    trackSelectionFactory = new RandomTrackSelection.Factory();
                }
                else
                {
                    ShowToast(Resource.String.error_unrecognized_abr_algorithm);
                    Finish();
                    return;
                }

                bool preferExtensionDecoders =
                    intent.GetBooleanExtra(PREFER_EXTENSION_DECODERS_EXTRA, false);
                int extensionRendererMode =
                    ((DemoApplication)Application).UseExtensionRenderers()
                        ? (preferExtensionDecoders ? DefaultRenderersFactory.ExtensionRendererModePrefer
                        : DefaultRenderersFactory.ExtensionRendererModeOn)
                        : DefaultRenderersFactory.ExtensionRendererModeOff;
                DefaultRenderersFactory renderersFactory =
                    new DefaultRenderersFactory(this, extensionRendererMode);

                trackSelector = new DefaultTrackSelector(trackSelectionFactory);
                trackSelector.SetParameters(trackSelectorParameters);
                lastSeenTrackGroupArray = null;

                player = ExoPlayerFactory.NewSimpleInstance(renderersFactory, trackSelector, drmSessionManager);

                eventLogger = new EventLogger(trackSelector);

                player.AddListener(new PlayerEventListener(this));
                player.PlayWhenReady = startAutoPlay;

                player.AddListener(eventLogger);

                // Cannot implement the AnalyticsListener because the binding doesn't work.

                //Todo: implement IAnalyticsListener
                //player.AddAnalyticsListener(eventLogger);

                player.AddAudioDebugListener(eventLogger);
                player.AddVideoDebugListener(eventLogger);

                player.AddMetadataOutput(eventLogger);
                //end Todo

                playerView.Player = player;
                playerView.SetPlaybackPreparer(this);
                debugViewHelper = new DebugTextViewHelper(player, debugTextView);
                debugViewHelper.Start();

                IMediaSource[] mediaSources = new IMediaSource[uris.Length];
                for (int i = 0; i < uris.Length; i++)
                {
                    mediaSources[i] = BuildMediaSource(uris[i], extensions[i]);
                }
                mediaSource =
                    mediaSources.Length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources);
                string adTagUristring = intent.GetStringExtra(AD_TAG_URI_EXTRA);
                if (adTagUristring != null)
                {
                    android.Net.Uri adTagUri = android.Net.Uri.Parse(adTagUristring);
                    if (!adTagUri.Equals(loadedAdTagUri))
                    {
                        ReleaseAdsLoader();
                        loadedAdTagUri = adTagUri;
                    }
                    IMediaSource adsMediaSource = CreateAdsMediaSource(mediaSource, android.Net.Uri.Parse(adTagUristring));
                    if (adsMediaSource != null)
                    {
                        mediaSource = adsMediaSource;
                    }
                    else
                    {
                        ShowToast(Resource.String.ima_not_loaded);
                    }
                }
                else
                {
                    ReleaseAdsLoader();
                }
            }
            bool haveStartPosition = startWindow != C.IndexUnset;

            if (haveStartPosition)
            {
                player.SeekTo(startWindow, startPosition);
            }
            player.Prepare(mediaSource, !haveStartPosition, false);
            UpdateButtonVisibilities();
        }