/// <summary>
        /// Navigates to the Video Player with the request MRL as parameter
        /// </summary>
        /// <param name="mrl">The stream MRL to be played</param>
        /// <returns></returns>
        public async Task PlayStream(string streamMrl)
        {
            Uri uri;

            try
            {
                uri = new Uri(streamMrl);
            }
            catch (UriFormatException ex)
            {
                var md = new MessageDialog(string.Format("{0} is invalid ({1})", streamMrl, ex.Message), "Invalid URI");
                await md.ShowAsync();

                return;
            }
            try
            {
                var stream = await Locator.MediaLibrary.LoadStreamFromDatabaseOrCreateOne(uri.ToString());

                LoadingMedia = Visibility.Visible;
                await Locator.MediaPlaybackViewModel.PlaybackService.SetPlaylist(new List <IMediaItem> {
                    stream
                }, true, true, stream);
            }
            catch (Exception e)
            {
                LogHelper.Log(StringsHelper.ExceptionToString(e));
                return;
            }
        }
        public override async void Execute(object parameter)
        {
            var selectedTracks = Locator.MusicLibraryVM.CurrentTrackCollection.SelectedTracks;

            foreach (var selectedItem in selectedTracks)
            {
                var trackItem = selectedItem as TrackItem;
                if (trackItem == null)
                {
                    continue;
                }
                await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () =>
                {
                    try
                    {
                        Locator.MediaLibrary.RemoveTrackInPlaylist(trackItem.Id,
                                                                   Locator.MusicLibraryVM.CurrentTrackCollection.Id);
                        Locator.MusicLibraryVM.CurrentTrackCollection.Remove(trackItem);
                    }
                    catch (Exception exception)
                    {
                        LogHelper.Log(StringsHelper.ExceptionToString(exception));
                    }
                });
            }
            await
            DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal,
                                            () => Locator.MusicLibraryVM.CurrentTrackCollection.SelectedTracks.Clear());
        }
 public async Task SetMediaTransportControlsInfo(string title)
 {
     await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () =>
     {
         try
         {
             if (_systemMediaTransportControls == null)
             {
                 return;
             }
             LogHelper.Log("PLAYVIDEO: Updating SystemMediaTransportControls");
             SystemMediaTransportControlsDisplayUpdater updater = _systemMediaTransportControls.DisplayUpdater;
             updater.Type = MediaPlaybackType.Video;
             _systemMediaTransportControls.IsPreviousEnabled = false;
             _systemMediaTransportControls.IsNextEnabled     = false;
             //Video metadata
             updater.VideoProperties.Title = title;
             //TODO: add full thumbnail suport
             updater.Thumbnail = null;
             updater.Update();
         }
         catch (Exception e)
         {
             LogHelper.Log(StringsHelper.ExceptionToString(e));
         }
     });
 }
示例#4
0
        public async Task AddTvShow(VideoItem episode)
        {
            episode.IsTvShow = true;
            try
            {
                TvShow show = Shows.FirstOrDefault(x => x.ShowTitle == episode.ShowTitle);
                if (show == null)
                {
                    // Generate a thumbnail for the show
                    await Locator.MediaLibrary.FetchVideoThumbnailOrWaitAsync(episode);

                    show = new TvShow(episode.ShowTitle);
                    show.Episodes.Add(episode);
                    Shows.Add(show);
                }
                else
                {
                    if (show.Episodes.FirstOrDefault(x => x.Id == episode.Id) == null)
                    {
                        await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => show.Episodes.Add(episode));
                    }
                }
            }
            catch (Exception e)
            {
                LogHelper.Log(StringsHelper.ExceptionToString(e));
            }
        }
示例#5
0
        private static async Task GetFilesFromSubFolders(StorageFolder folder, List <StorageFile> files)
        {
            try
            {
                var items = await folder.GetItemsAsync();

                foreach (IStorageItem storageItem in items)
                {
                    if (storageItem.IsOfType(StorageItemTypes.Folder))
                    {
                        await GetFilesFromSubFolders(storageItem as StorageFolder, files);
                    }
                    else if (storageItem.IsOfType(StorageItemTypes.File))
                    {
                        var file = storageItem as StorageFile;
                        if (VLCFileExtensions.VideoExtensions.Contains(file.FileType.ToLower()))
                        {
                            files.Add(file);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogHelper.Log(StringsHelper.ExceptionToString(e));
            }
        }
 async Task GetAllMusicFolders()
 {
     try
     {
         StorageFolder musicLibrary = KnownFolders.MusicLibrary;
         LogHelper.Log("Searching for music from Phone MusicLibrary ...");
         await CreateDatabaseFromMusicFolder(musicLibrary);
     }
     catch (Exception e)
     {
         LogHelper.Log(StringsHelper.ExceptionToString(e));
     }
 }
示例#7
0
        public async Task <StorageItemThumbnail> GetThumbnail(StorageFile file)
        {
            StorageItemThumbnail thumb = null;

            try
            {
                thumb = await file.GetThumbnailAsync(ThumbnailMode.VideosView);
            }
            catch (Exception e)
            {
                LogHelper.Log("Error getting thumbnail: ");
                LogHelper.Log(StringsHelper.ExceptionToString(e));
            }
            return(thumb);
        }
示例#8
0
 public async Task PopulateAlbums(ArtistItem artist)
 {
     try
     {
         var albums = musicDatabase.LoadAlbumsFromArtistId(artist.Id).ToObservable();
         await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () =>
         {
             artist.Albums = albums;
         });
     }
     catch (Exception e)
     {
         LogHelper.Log(StringsHelper.ExceptionToString(e));
     }
 }
示例#9
0
 public async Task PopulateTracks(AlbumItem album)
 {
     try
     {
         var tracks = musicDatabase.LoadTracksFromAlbumId(album.Id);
         await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () =>
         {
             album.Tracks = tracks;
         });
     }
     catch (Exception e)
     {
         LogHelper.Log(StringsHelper.ExceptionToString(e));
     }
 }
示例#10
0
        public Task Initialize(object o = null)
        {
            return(DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                var param = new List <string>
                {
                    "-I",
                    "dummy",
                    "--no-osd",
                    "--verbose=3",
                    "--no-stats",
                    "--avcodec-fast",
                    string.Format("--freetype-font={0}\\NotoSans-Regular.ttf", Windows.ApplicationModel.Package.Current.InstalledLocation.Path),
                    "--subsdec-encoding",
                    Locator.SettingsVM.SubtitleEncodingValue == "System" ? "" : Locator.SettingsVM.SubtitleEncodingValue
                };

                // So far, this NEEDS to be called from the main thread
                try
                {
                    Instance = new Instance(param, App.RootPage.SwapChainPanel);
                    Instance?.setDialogHandlers(
                        async(title, text) =>
                    {
                        await DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => await DialogHelper.DisplayDialog(title, text));
                    },
                        async(dialog, title, text, defaultUserName, askToStore) =>
                    {
                        await DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => await DialogHelper.DisplayDialog(title, text, dialog, defaultUserName, askToStore));
                    },

                        async(dialog, title, text, qType, cancel, action1, action2) =>
                    {
                        await DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => await DialogHelper.DisplayDialog(title, text, dialog, qType, cancel, action1, action2));
                    },

                        (dialog, title, text, intermidiate, position, cancel) => { },
                        (dialog) => dialog.dismiss(),
                        (dialog, position, text) => { });
                    PlayerInstanceReady.TrySetResult(Instance != null);
                }
                catch (Exception e)
                {
                    LogHelper.Log("VLC Service : Couldn't create VLC Instance\n" + StringsHelper.ExceptionToString(e));
                    ToastHelper.Basic(Strings.FailStartVLCEngine);
                }
            }));
        }
示例#11
0
        public Task Initialize()
        {
            return(DispatchHelper.InvokeInUIThread(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                var param = new List <string>
                {
                    "-I",
                    "dummy",
                    "--no-osd",
                    "--verbose=3",
                    "--no-stats",
                    "--avcodec-fast",
                    "--subsdec-encoding",
                    Locator.SettingsVM.SubtitleEncodingValue == "System" ? "" : Locator.SettingsVM.SubtitleEncodingValue,
                    DeviceHelper.GetDeviceType() == DeviceTypeEnum.Phone ? "--deinterlace-mode=bob" : string.Empty,
                    "--aout=winstore",
                    string.Format("--keystore-file={0}\\keystore", ApplicationData.Current.LocalFolder.Path),
                };

                // So far, this NEEDS to be called from the main thread
                try
                {
                    App.RootPage.SwapChainPanel.CompositionScaleChanged += SwapChainPanel_CompositionScaleChanged;
                    App.RootPage.SwapChainPanel.SizeChanged += SwapChainPanel_SizeChanged;
                    Instance = new Instance(param, App.RootPage.SwapChainPanel);
                    Instance?.setDialogHandlers(
                        async(title, text) => await _dialogService.ShowErrorDialog(title, text),
                        async(dialog, title, text, defaultUserName, askToStore) => await _dialogService.ShowLoginDialog(dialog, title, text, defaultUserName, askToStore),
                        async(dialog, title, text, qType, cancel, action1, action2) => await _dialogService.ShowQuestionDialog(dialog, title, text, qType, cancel, action1, action2),
                        (dialog, title, text, intermidiate, position, cancel) => { },
                        async(dialog) => await _dialogService.CancelCurrentDialog(),
                        (dialog, position, text) => { }
                        );

                    // Audio device management also needs to be called from the main thread
                    MediaDevice.DefaultAudioRenderDeviceChanged += onDefaultAudioRenderDeviceChanged;
                    PlayerInstanceReady.TrySetResult(Instance != null);
                }
                catch (Exception e)
                {
                    LogHelper.Log("VLC Service : Couldn't create VLC Instance\n" + StringsHelper.ExceptionToString(e));
                    ToastHelper.Basic(Strings.FailStartVLCEngine);
                }
            }));
        }
 public async Task ClearMediaTransportControls()
 {
     await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () =>
     {
         try
         {
             if (_systemMediaTransportControls == null)
             {
                 return;
             }
             LogHelper.Log("PLAYVIDEO: Updating SystemMediaTransportControls");
             SystemMediaTransportControlsDisplayUpdater updater = _systemMediaTransportControls.DisplayUpdater;
             updater.ClearAll();
         }
         catch (Exception e)
         {
             LogHelper.Log(StringsHelper.ExceptionToString(e));
         }
     });
 }
示例#13
0
        public async Task <bool> DiscoverMediaItemOrWaitAsync(StorageFile storageItem, bool isCameraRoll)
        {
            await MediaItemDiscovererSemaphoreSlim.WaitAsync();

            bool success;

            try
            {
                success = await ParseMediaFile(storageItem, isCameraRoll);
            }
            catch (Exception e)
            {
                LogHelper.Log(StringsHelper.ExceptionToString(e));
                success = false;
            }
            finally
            {
                MediaItemDiscovererSemaphoreSlim.Release();
            }
            return(success);
        }
示例#14
0
        public async Task FetchVideoThumbnailOrWaitAsync(VideoItem videoVm)
        {
            await VideoThumbnailFetcherSemaphoreSlim.WaitAsync();

            try
            {
                await GenerateThumbnail(videoVm);

                if (videoVm.Type == ".mkv")
                {
                    await Locator.VideoMetaService.GetMoviePicture(videoVm).ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                LogHelper.Log(StringsHelper.ExceptionToString(e));
            }
            finally
            {
                VideoThumbnailFetcherSemaphoreSlim.Release();
            }
        }
示例#15
0
        public Task Initialize(object o = null)
        {
            return(DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                var param = new List <string>
                {
                    "-I",
                    "dummy",
                    "--no-osd",
                    "--verbose=3",
                    "--no-stats",
                    "--avcodec-fast",
                    string.Format("--freetype-font={0}\\NotoSans-Regular.ttf", Windows.ApplicationModel.Package.Current.InstalledLocation.Path),
                    "--subsdec-encoding",
                    Locator.SettingsVM.SubtitleEncodingValue == "System" ? "" : Locator.SettingsVM.SubtitleEncodingValue,
                    "--aout=winstore",
                    string.Format("--keystore-file={0}\\keystore", ApplicationData.Current.LocalFolder.Path),
                };

                // So far, this NEEDS to be called from the main thread
                try
                {
                    Instance = new Instance(param, App.RootPage.SwapChainPanel);
                    Instance?.setDialogHandlers(
                        async(title, text) =>
                    {
                        await DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                        {
                            await VLCDialog.WaitForDialogLock();
                            CurrentDialog = new VLCDialog(title, text);
                            await CurrentDialog.ShowAsync();
                        });
                    },
                        async(dialog, title, text, defaultUserName, askToStore) =>
                    {
                        await DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                        {
                            await VLCDialog.WaitForDialogLock();
                            CurrentDialog = new VLCDialog(title, text, dialog, defaultUserName, askToStore);
                            await CurrentDialog.ShowAsync();
                        });
                    },

                        async(dialog, title, text, qType, cancel, action1, action2) =>
                    {
                        await DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                        {
                            if (qType == Question.warning)
                            {
                                dialog.postAction(1);
                                return;
                            }
                            await VLCDialog.WaitForDialogLock();
                            CurrentDialog = new VLCDialog(title, text, dialog, qType, cancel, action1, action2);
                            await CurrentDialog.ShowAsync();
                        });
                    },

                        (dialog, title, text, intermidiate, position, cancel) => { },
                        async(dialog) =>
                    {
                        await DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => CurrentDialog.Cancel());
                    },
                        (dialog, position, text) => { });

                    // Audio device management also needs to be called from the main thread
                    AudioClient = new AudioDeviceHandler(AudioDeviceID);
                    MediaDevice.DefaultAudioRenderDeviceChanged += onDefaultAudioRenderDeviceChanged;
                    PlayerInstanceReady.TrySetResult(Instance != null);
                }
                catch (Exception e)
                {
                    LogHelper.Log("VLC Service : Couldn't create VLC Instance\n" + StringsHelper.ExceptionToString(e));
                    ToastHelper.Basic(Strings.FailStartVLCEngine);
                }
            }));
        }