Example #1
0
        public static PageDeactivator Inactivate(bool makePageInactive)
        {
            var s = new PageDeactivator();

            s.DoIt(makePageInactive);
            return(s);
        }
Example #2
0
        private static bool CancelPlay(bool manualActivatePage)
        {
            lock (typeof(YouTube))
            {
                if (_oldState == null && _cancellationToken == null)
                    return false;

                if (_cancellationToken != null)
                {
                    _cancellationToken.Cancel();
                    _cancellationToken.Dispose();
                    _cancellationToken = null;
                }

                if (!manualActivatePage && _oldState != null)
                {
                    _oldState.Revert();
                    SystemTray.ProgressIndicator.IsVisible = false;
                    _oldState = null;
                }

                return true;
            }
        }
Example #3
0
        /// <summary>Plays the YouTube video in the Windows Phone's external player. 
        /// Disables the current page and shows a progress indicator until 
        /// the YouTube movie URI has been loaded and the video playback starts. </summary>
        /// <param name="youTubeId">The YouTube ID</param>
        /// <param name="manualActivatePage">if true add YouTube.CancelPlay() in OnNavigatedTo() of the page (better)</param>
        /// <param name="maxQuality">The maximum allowed video quality. </param>
        /// <returns>Awaitable task. </returns>
        public static async Task PlayWithPageDeactivationAsync(string youTubeId, bool manualActivatePage, YouTubeQuality maxQuality)
        {
            PhoneApplicationPage page;

            lock (typeof(YouTube))
            {
                if (_oldState != null)
                    return;

                if (SystemTray.ProgressIndicator == null)
                    SystemTray.ProgressIndicator = new ProgressIndicator();

                SystemTray.ProgressIndicator.IsVisible = true;
                SystemTray.ProgressIndicator.IsIndeterminate = true;

                page = Environment.PhoneApplication.CurrentPage;

                _oldState = PageDeactivator.Inactivate();
                _cancellationToken = new CancellationTokenSource();
            }

            try
            {
                await PlayAsync(youTubeId, maxQuality, _cancellationToken.Token);
                if (page == Environment.PhoneApplication.CurrentPage)
                    CancelPlay(manualActivatePage);
            }
            catch (Exception)
            {
                if (page == Environment.PhoneApplication.CurrentPage)
                    CancelPlay(false);
                throw;
            }
        }
Example #4
0
        private static bool CancelPlay(bool manualActivate)
        {
            lock (typeof(YouTube))
            {
                if (oldState == null && httpResponse == null)
                    return false;

                if (httpResponse != null)
                {
                    httpResponse.Abort();
                    httpResponse = null;
                }

                if (!manualActivate && oldState != null)
                {
                    oldState.Revert();
                    SystemTray.ProgressIndicator.IsVisible = false;
                    oldState = null;
                }

                return true;
            }
        }
Example #5
0
        /// <summary>
        /// This method disables the current page and shows a progress indicator until the youtube movie url has been loaded and starts
        /// </summary>
        /// <param name="youTubeId"></param>
        /// <param name="manualActivatePage">if true add YouTube.CancelPlay() in OnNavigatedTo() of the page (better)</param>
        /// <param name="maxQuality"></param>
        /// <param name="completed"></param>
        public static void Play(string youTubeId, bool manualActivatePage, YouTubeQuality maxQuality = YouTubeQuality.Quality480P, Action<Exception> completed = null)
        {
            //Debug.WriteLine("Play(string youTubeId, bool manualActivatePage, YouTubeQuality maxQuality = YouTubeQuality.Quality480P, Action<Exception> completed = null)");
            lock (typeof(YouTube))
            {
                if (oldState != null)
                    return;

                if (SystemTray.ProgressIndicator == null)
                    SystemTray.ProgressIndicator = new ProgressIndicator();

                SystemTray.ProgressIndicator.IsVisible = true;
                SystemTray.ProgressIndicator.IsIndeterminate = true;

                var page = PhonePage.CurrentPage;
                oldState = PageDeactivator.Inactivate();
                httpResponse = Play(youTubeId, YouTubeQuality.Quality480P, ex => Deployment.Current.Dispatcher.BeginInvoke(
                    delegate
                    {
                        if (page == PhonePage.CurrentPage) // !user navigated away
                            CancelPlay(manualActivatePage);

                        if (completed != null)
                            completed(ex);
                    }));
            }
        }
Example #6
0
		public static PageDeactivator Inactivate(bool makePageInactive)
		{
			var s = new PageDeactivator();
			s.DoIt(makePageInactive);
			return s;
		}
Example #7
0
        /// <summary>
        /// This method disables the current page and shows a progress indicator until the youtube movie url has been loaded and starts
        /// </summary>
        /// <param name="youTubeId"></param>
        /// <param name="manualActivatePage">if true add YouTube.CancelPlay() in OnNavigatedTo() of the page (better)</param>
        /// <param name="maxQuality"></param>
        /// <param name="onFailure"></param>
        public static void Play(string youTubeId, bool manualActivatePage, YouTubeQuality maxQuality = YouTubeQuality.Quality480P, Action<Exception> onFailure = null)
        {
            lock (typeof(YouTube))
            {
                if (oldState != null)
                    return;

                if (SystemTray.ProgressIndicator == null)
                    SystemTray.ProgressIndicator = new ProgressIndicator();

                SystemTray.ProgressIndicator.IsVisible = true;
                SystemTray.ProgressIndicator.IsIndeterminate = true;

                var page = PhoneApplication.CurrentPage;
                oldState = PageDeactivator.Inactivate();
                httpResponse = Play(youTubeId, YouTubeQuality.Quality480P, ex => Deployment.Current.Dispatcher.BeginInvoke(
                    delegate
                    {
                        if (page != PhoneApplication.CurrentPage) // user navigated away
                            return;

                        if (ex != null && onFailure != null)
                        {
                            onFailure(ex);
                            CancelPlay(false);
                        }
                        else
                            CancelPlay(manualActivatePage);
                    }));
            }
        }