private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (videoId != null)
            {
                video = business.GetVideoById(videoId.Value);
                if (video.MediaId == Guid.Empty)
                {
                    throw new InvalidDataException("This Media information has an invalid empty GUID.");
                }
            }
            else
            {
                video = business.GetVideoByFileName(fileName);
                if (video == null)
                {
                    video              = business.NewVideo();
                    video.FileName     = fileName;
                    video.MediaTypeId  = (int)EditVideoBusiness.GetFileType(fileName);
                    video.DownloadName = System.IO.Path.GetFileNameWithoutExtension(fileName);
                    isNew              = true;
                }
            }

            this.DataContext          = video;
            CategoryCombo.ItemsSource = business.GetCategories(video.MediaTypeId);
            Custom1Combo.ItemsSource  = business.GetCustomRatingCategories();
            Custom2Combo.ItemsSource  = Custom1Combo.ItemsSource;
            ratingBusiness            = business.GetRatings(video);
            RatingsGrid.DataContext   = ratingBusiness;
            EditRating_LostFocus(null, null);

            if (video.FileName != null)
            {
                if (File.Exists(Settings.NaturalGroundingFolder + video.FileName))
                {
                    await LoadMediaInfoAsync();
                }
                else
                {
                    // Try to auto-attach same path with different extension.
                    if (!EditPlaylistBusiness.AutoAttachFile(video, Path.ChangeExtension(video.FileName, null)))
                    {
                        fileNotFound   = true;
                        ErrorText.Text = "File not found.";
                    }
                }
            }
        }
Beispiel #2
0
        public async Task DownloadAndPlaySample(string artist, string title)
        {
            EditVideoBusiness FindVideoBusiness = new EditVideoBusiness();
            Media             sample            = FindVideoBusiness.GetVideoByTitle(MediaType.Video, artist, title);

            if (sample != null)
            {
                if (sample.FileName != null && File.Exists(Settings.NaturalGroundingFolder + sample.FileName))
                {
                    // File exists, play.
                    await PlayVideo(sample);
                }
                else if (sample.DownloadUrl != null)
                {
                    // File doesn't exist, download.
                    // It will only auto-play if user is still on the same page.
                    downloadPage = currentPage;
                    await SessionCore.Instance.Business.DownloadManager.DownloadVideoAsync(sample, -1, DownloadBusiness_DownloadCompleted);
                }
            }
        }