Пример #1
0
 public static async Task FetchVideoThumbnailOrWaitAsync(VideoItem videoVm)
 {
     await VideoThumbnailFetcherSemaphoreSlim.WaitAsync();
     try
     {
         var isChanged = await VideoLibraryManagement.GenerateThumbnail(videoVm);
         if (isChanged)
             await Locator.VideoLibraryVM.VideoRepository.Update(videoVm);
     }
     finally
     {
         VideoThumbnailFetcherSemaphoreSlim.Release();
     }
 }
Пример #2
0
        // Returns false is no snapshot generation was required, true otherwise
        public static async Task<Boolean> GenerateThumbnail(VideoItem videoItem)
        {
            if (videoItem.HasThumbnail)
                return false;
            try
            {
                if (Locator.MediaPlaybackViewModel.ContinueIndexing != null)
                {
                    await Locator.MediaPlaybackViewModel.ContinueIndexing.Task;
                    Locator.MediaPlaybackViewModel.ContinueIndexing = null;
                }
#if WINDOWS_PHONE_APP
                if (MemoryUsageHelper.PercentMemoryUsed() > MemoryUsageHelper.MaxRamForResourceIntensiveTasks)
                    return false;
#endif
                WriteableBitmap image = null;
                StorageItemThumbnail thumb = null;
                // If file is a mkv, we save the thumbnail in a VideoPic folder so we don't consume CPU and resources each launch
                if (VLCFileExtensions.MFSupported.Contains(videoItem.File.FileType.ToLower()))
                {
                    thumb = await ThumbsService.GetThumbnail(videoItem.File).ConfigureAwait(false);
                }
                // If MF thumbnail generation failed or wasn't supported:
                if (thumb == null)
                {
                    var res = await ThumbsService.GetScreenshot(videoItem.File).ConfigureAwait(false);
                    if (res == null)
                        return true;
                    image = res.Bitmap();
                    await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => videoItem.Duration = TimeSpan.FromMilliseconds(res.Length()));
                }
                if (thumb != null || image != null)
                {
                    // RunAsync won't await on the lambda it receives, so we need to do it ourselves
                    var tcs = new TaskCompletionSource<bool>();
                    await App.Dispatcher.RunAsync(CoreDispatcherPriority.Low, async () =>
                    {
                        if (thumb != null)
                        {
                            image = new WriteableBitmap((int)thumb.OriginalWidth, (int)thumb.OriginalHeight);
                            await image.SetSourceAsync(thumb);
                        }
                        await DownloadAndSaveHelper.WriteableBitmapToStorageFile(image, videoItem.Id.ToString());
                        videoItem.ThumbnailPath = String.Format("{0}{1}.jpg", Strings.VideoPicFolderPath, videoItem.Id);
                        tcs.SetResult(true);
                    });
                    await tcs.Task;
                }
                videoItem.HasThumbnail = true;
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex.ToString());
            }
            return false;
        }
Пример #3
0
 public static async Task AddTvShow(String name, VideoItem episode)
 {
     try
     {
         TvShow show = Locator.VideoLibraryVM.Shows.FirstOrDefault(x => x.ShowTitle == name);
         if (show == null)
         {
             show = new TvShow(name);
             await DispatchHelper.InvokeAsync(() =>
             {
                 show.Episodes.Add(episode);
                 Locator.VideoLibraryVM.Shows.Add(show);
                 if (Locator.VideoLibraryVM.Shows.Count == 1)
                     Locator.VideoLibraryVM.CurrentShow = Locator.VideoLibraryVM.Shows[0];
             });
         }
         else
         {
             if (show.Episodes.FirstOrDefault(x => x.Id == episode.Id) == null)
                 await DispatchHelper.InvokeAsync(() => show.Episodes.Add(episode));
         }
     }
     catch (Exception e)
     {
         ExceptionHelper.CreateMemorizedException("VideoLibaryManagement.AddTvShow", e);
     }
 }
Пример #4
0
 public Task Update(VideoItem video)
 {
     var connection = new SQLiteAsyncConnection(DbPath);
     return connection.UpdateAsync(video);
 }
Пример #5
0
 public Task Insert(VideoItem item)
 {
     var conn = new SQLiteAsyncConnection(DbPath);
     return conn.InsertAsync(item);
 }
 /// <summary>
 /// Navigates to the Video Player screen with the requested file a parameter.
 /// </summary>
 /// <param name="file">The file to be played.</param>
 /// <param name="token">Token is for files that are NOT in the sandbox, such as files taken from the filepicker from a sd card but not in the Video/Music folder.</param>
 public async Task PlayVideoFile(StorageFile file, string token = null)
 {
     Locator.NavigationService.Go(VLCPage.VideoPlayerPage);
     VideoItem videoVm = new VideoItem();
     await videoVm.Initialize(file);
     if (token != null)
         videoVm.Token = token;
     Locator.VideoVm.CurrentVideo = videoVm;
     await PlaylistHelper.Play(videoVm);
 }
Пример #7
0
 public async Task Add(VideoItem videoItem, bool isPlayingPlaylist)
 {
     if (Playlist.FirstOrDefault(x => x.Path == videoItem.Path) != null) return;
     Playlist.Add(videoItem);
 }