Exemple #1
0
        private QuickMixPlaylistFactory(
            int mediaId,
            MediaType mediaType,
            EQuickMixMode mode,
            out HRESULT hr)
            : base(true)
        {
            TimeSpan maxBatchTimeout = TimeSpan.FromMilliseconds(5000.0);

            int[] seedMediaIds = new int[1] {
                mediaId
            };
            this._mode = mode;
            QuickMix instance = QuickMix.Instance;

            hr = instance.CreateSession(this._mode, seedMediaIds, (EMediaTypes)mediaType, out this._quickMixSession);
            if (!hr.IsSuccess)
            {
                return;
            }
            this._shouldDisposeSession = true;
            if (this._mode != EQuickMixMode.eQuickMixModeSimilarArtists)
            {
                PerfTrace.TraceUICollectionEvent(UICollectionEvent.QuickMixBegin, "");
            }
            hr = this._quickMixSession.GetSimilarMedia((uint)ClientConfiguration.QuickMix.DefaultPlaylistLength, maxBatchTimeout, new SimilarMediaBatchHandler(this.SimilarBatchHandler), new BatchEndHandler(this.BatchEndHandler));
        }
Exemple #2
0
        private QuickMixPlaylistFactory(
            Guid serviceMediaId,
            MediaType mediaType,
            EQuickMixMode mode,
            out HRESULT hr)
            : base(true)
        {
            TimeSpan maxBatchTimeout = TimeSpan.FromMilliseconds(10000.0);

            this._mode = mode;
            QuickMix instance = QuickMix.Instance;

            hr = instance.CreateSession(this._mode, serviceMediaId, (EMediaTypes)mediaType, null, out this._quickMixSession);
            if (!hr.IsSuccess)
            {
                return;
            }
            this._shouldDisposeSession = true;
            hr = this._quickMixSession.GetSimilarMedia((uint)ClientConfiguration.QuickMix.DefaultPlaylistLength, maxBatchTimeout, new SimilarMediaBatchHandler(this.SimilarBatchHandler), new BatchEndHandler(this.BatchEndHandler));
        }
        private void AddQuickMixItemsWorker(IList items)
        {
            QuickMix    instance   = QuickMix.Instance;
            HRESULT     hresult    = HRESULT._S_OK;
            EMediaTypes eMediaType = EMediaTypes.eMediaTypeInvalid;

            this._quickMixNoResultsStringId = StringId.IDS_QUICKMIX_ITEM_CREATION_UNAVAILABLE_TEXT;
            if (this._quickMixSession != null)
            {
                this._quickMixSession.Dispose();
                this._quickMixSession = null;
            }
            NotificationArea.Instance.RemoveAll(NotificationTask.QuickMix, NotificationState.OneShot);
            if (items[0] is Artist artist)
            {
                this._quickMixNoResultsStringId = StringId.IDS_QUICKMIX_ARTIST_CREATION_UNAVAILABLE_TEXT;
                hresult = instance.CreateSession(EQuickMixMode.eQuickMixModeNowPlaying, artist.Id, EMediaTypes.eMediaTypePersonArtist, artist.Title, out this._quickMixSession);
                if (hresult.IsSuccess)
                {
                    string text = string.Format(Shell.LoadString(StringId.IDS_QUICKMIX_NOTIFICATION_CREATION_BUSY_ONE_PARAM_TEXT), artist.Title);
                    this._quickMixCreatingNotification = new QuickMixNotification(Shell.LoadString(StringId.IDS_QUICKMIX_NOTIFICATION_CREATION_BUSY_TITLE), text, NotificationState.OneShot, false, 15000);
                    SQMLog.Log(SQMDataId.QuickMixRadioPlays, 1);
                }
            }
            if (hresult.IsSuccess && items[0] is LibraryDataProviderItemBase providerItemBase)
            {
                if (providerItemBase.TypeName == "Artist")
                {
                    eMediaType = EMediaTypes.eMediaTypePersonArtist;
                    this._quickMixNoResultsStringId = StringId.IDS_QUICKMIX_ARTIST_CREATION_UNAVAILABLE_TEXT;
                    string property = (string)providerItemBase.GetProperty("Title");
                    string text     = string.Format(Shell.LoadString(StringId.IDS_QUICKMIX_NOTIFICATION_CREATION_BUSY_ONE_PARAM_TEXT), property);
                    this._quickMixCreatingNotification = new QuickMixNotification(Shell.LoadString(StringId.IDS_QUICKMIX_NOTIFICATION_CREATION_BUSY_TITLE), text, NotificationState.OneShot, false, 15000);
                }
                else if (providerItemBase.TypeName == "Album")
                {
                    eMediaType = EMediaTypes.eMediaTypeAudioAlbum;
                    this._quickMixNoResultsStringId = StringId.IDS_QUICKMIX_ALBUM_CREATION_UNAVAILABLE_TEXT;
                    string property1 = (string)providerItemBase.GetProperty("ArtistName");
                    string property2 = (string)providerItemBase.GetProperty("Title");
                    string text      = string.Format(Shell.LoadString(StringId.IDS_QUICKMIX_NOTIFICATION_CREATION_BUSY_TWO_PARAM_TEXT), property1, property2);
                    this._quickMixCreatingNotification = new QuickMixNotification(Shell.LoadString(StringId.IDS_QUICKMIX_NOTIFICATION_CREATION_BUSY_TITLE), text, NotificationState.OneShot, false, 15000);
                }
                else if (providerItemBase.TypeName == "Track")
                {
                    eMediaType = EMediaTypes.eMediaTypeAudio;
                    this._quickMixNoResultsStringId = StringId.IDS_QUICKMIX_SONG_CREATION_UNAVAILABLE_TEXT;
                    string property1 = (string)providerItemBase.GetProperty("ArtistName");
                    string property2 = (string)providerItemBase.GetProperty("Title");
                    string text      = string.Format(Shell.LoadString(StringId.IDS_QUICKMIX_NOTIFICATION_CREATION_BUSY_TWO_PARAM_TEXT), property1, property2);
                    this._quickMixCreatingNotification = new QuickMixNotification(Shell.LoadString(StringId.IDS_QUICKMIX_NOTIFICATION_CREATION_BUSY_TITLE), text, NotificationState.OneShot, false, 15000);
                }
                int[] seedMediaIds = new int[1]
                {
                    (int)providerItemBase.GetProperty("LibraryId")
                };
                hresult = instance.CreateSession(EQuickMixMode.eQuickMixModeNowPlaying, seedMediaIds, eMediaType, out this._quickMixSession);
                SQMLog.Log(SQMDataId.QuickMixLocalPlays, 1);
            }
            if (hresult.IsSuccess)
            {
                if (this._quickMixSession != null)
                {
                    hresult            = this._quickMixSession.GetSimilarMedia((uint)ClientConfiguration.QuickMix.DefaultPlaylistLength, TimeSpan.FromMilliseconds(15000.0), new SimilarMediaBatchHandler(this.SimilarBatchHandler), new BatchEndHandler(this.BatchEndHandler));
                    this._quickMixType = this._quickMixSession.GetQuickMixType();
                    this._quickMixSession.GetPlaylistTitle(out this._quickMixTitle);
                }
                else
                {
                    hresult = HRESULT._E_UNEXPECTED;
                }
            }
            if (hresult.IsSuccess)
            {
                NotificationArea.Instance.Add(_quickMixCreatingNotification);
            }
            else
            {
                if (this._quickMixSession != null)
                {
                    this._quickMixSession.Dispose();
                    this._quickMixSession = null;
                }
                if (hresult.Int == HRESULT._ZUNE_E_QUICKMIX_MEDIA_NOT_FOUND)
                {
                    MessageBox.Show(Shell.LoadString(StringId.IDS_QUICKMIX_CREATION_UNAVAILABLE_NO_RESULTS_TITLE), Shell.LoadString(this._quickMixNoResultsStringId), null);
                }
                else
                {
                    ErrorDialogInfo.Show(hresult.Int, Shell.LoadString(StringId.IDS_QUICKMIX_CREATION_UNAVAILABLE_NO_RESULTS_TITLE));
                }
            }
        }