コード例 #1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
            {
                var statusbar = StatusBar.GetForCurrentView();
                statusbar.BackgroundColor = new Windows.UI.Color()
                {
                    R = 153, G = 122, B = 165
                };
                statusbar.BackgroundOpacity = 1;
                statusbar.ForegroundColor   = Windows.UI.Colors.White;
            }

            int    paramIndex = e.Parameter.ToString().IndexOf("|");
            string id         = e.Parameter.ToString().Substring(0, paramIndex);

            MovieTitle = e.Parameter.ToString().Substring(paramIndex + 1);

            Cast      = new ObservableCollection <ExtendedVideoCast>();
            IsLoading = true;
            Genres    = "";

            try
            {
                var movie = await App.Context.Connection.Kodi.VideoLibrary.GetMovieDetailsAsync(int.Parse(id));

                Movie = new ExtendedVideoDetailsMovie(movie, false);

                foreach (var cast in movie.Cast)
                {
                    Cast.Add(new ExtendedVideoCast(cast));
                }

                Genres   = Helpers.Combine(movie.Genre);
                Director = Helpers.Combine(movie.Director);
                Studio   = Helpers.Combine(movie.Studio);
                Rating   = movie.Rating / 2;
                Votes    = string.Format(_resourceLoader.GetString("/movies/VotesFormat"), movie.Votes);
                Minutes  = movie.Runtime / 60;
                if (Movie.Movie.ImdbNumber == null)
                {
                    ButtonSeeImdb.Visibility = Visibility.Collapsed;
                }

                TrailerVisibility = Visibility.Collapsed;
                if (!string.IsNullOrWhiteSpace(Movie.Movie.Trailer))
                {
                    TrailerVisibility = Visibility.Visible;
                    Regex regex = new Regex(@"video[_]?id=(?<youtubeId>[^&]*)");
                    if (regex.IsMatch(Movie.Movie.Trailer))
                    {
                        Match match = regex.Match(Movie.Movie.Trailer);
                        if (match.Groups["youtubeId"].Success)
                        {
                            string youtubeId = match.Groups["youtubeId"].Value;
                            ImageTrailer = YouTube.GetThumbnailUri(youtubeId);

                            var urlTrailer = await YouTube.GetVideoUriAsync(youtubeId, YouTubeQuality.Quality1080P);

                            PlaybackList = new MediaPlaybackList();
                            PlaybackList.Items.Add(new MediaPlaybackItem(MediaSource.CreateFromUri(urlTrailer.Uri)));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                App.TrackException(ex);
                var dialog = new MessageDialog(_resourceLoader.GetString("GlobalErrorMessage"), _resourceLoader.GetString("ApplicationTitle"));
                await dialog.ShowAsync();
            }
            finally
            {
                IsLoading = false;
            }

            if (!string.IsNullOrWhiteSpace(Movie?.Movie?.Thumbnail))
            {
                ImageUrl = await Helpers.LoadImageUrl(Movie.Movie.Thumbnail);
            }

            if (!string.IsNullOrWhiteSpace(Movie?.Movie?.FanArt))
            {
                FanArt = await Helpers.LoadImageUrl(Movie.Movie.FanArt);
            }
        }
コード例 #2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            string movieTitle;
            string id;
            int    intId;

            if (!NavigationContext.QueryString.TryGetValue("id", out id) ||
                !NavigationContext.QueryString.TryGetValue("title", out movieTitle) ||
                !int.TryParse(id, out intId))
            {
                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                }

                return;
            }

            Cast       = new ObservableCollection <ExtendedVideoCast>();
            MovieTitle = HttpUtility.UrlDecode(movieTitle);
            IsLoading  = true;
            Genres     = "";

            try
            {
                var movie = await App.Context.Connection.Xbmc.VideoLibrary.GetMovieDetailsAsync(intId);

                Movie = new ExtendedVideoDetailsMovie(movie, false);

                foreach (var cast in movie.Cast.Take(5))
                {
                    Cast.Add(new ExtendedVideoCast(cast));
                }

                Genres   = Helpers.Combine(movie.Genre);
                Director = Helpers.Combine(movie.Director);
                Studio   = Helpers.Combine(movie.Studio);
                Rating   = movie.Rating / 2;
                Votes    = string.Format(AppResources.Page_Tv_Shows_Votes_Format, movie.Votes);
                Minutes  = movie.Runtime / 60;
                if (Movie.Movie.ImdbNumber == null)
                {
                    ButtonSeeImdb.Visibility = Visibility.Collapsed;
                }

                TrailerVisibility = Visibility.Collapsed;
                if (!string.IsNullOrWhiteSpace(Movie.Movie.Trailer))
                {
                    TrailerVisibility = Visibility.Visible;
                    int index = Movie.Movie.Trailer.IndexOf("videoid=", StringComparison.Ordinal);
                    if (index < 0)
                    {
                        index = Movie.Movie.Trailer.IndexOf("video_id=", StringComparison.Ordinal);
                    }
                    _youtubeId = Movie.Movie.Trailer.Substring(index);
                    index      = _youtubeId.IndexOf('=');
                    _youtubeId = _youtubeId.Substring(index + 1);

                    ImageTrailer = YouTube.GetThumbnailUri(_youtubeId);
                }
            }
            catch (Exception ex)
            {
                App.TrackException(ex);
                MessageBox.Show(AppResources.Global_Error_Message, AppResources.ApplicationTitle, MessageBoxButton.OK);
            }
            finally
            {
                IsLoading = false;
            }

            if (Movie?.Movie != null && !string.IsNullOrWhiteSpace(Movie.Movie.Thumbnail))
            {
                ImageUrl = await Helpers.LoadImageUrl(Movie.Movie.Thumbnail);
            }
        }