private async void ConnectToLastFM_Click(object sender, RoutedEventArgs e) { LastFMScrobbler lastFm = new LastFMScrobbler(App.ApiKeyLastFm, "bd9ad107438d9107296ef799703d478e"); string pseudo = (string)ApplicationSettingsHelper.ReadSettingsValue("LastFmUserName"); string pd = (string)ApplicationSettingsHelper.ReadSettingsValue("LastFmPassword"); if (string.IsNullOrEmpty(pseudo) || string.IsNullOrEmpty(pd)) { return; } ErrorConnectLastFmTextBox.Text = "Connecting"; ErrorConnectLastFmTextBox.Visibility = Visibility.Visible; ErrorConnectLastFmTextBox.Foreground = new SolidColorBrush(Colors.Black); var success = await lastFm.ConnectOperation(pseudo, pd); if (success) { ErrorConnectLastFmTextBox.Text = ""; ErrorConnectLastFmTextBox.Visibility = Visibility.Collapsed; ToastHelper.Basic("Congrats! You're connected to Last.Fm!"); Locator.SettingsVM.LastFmIsConnected = true; } else { ErrorConnectLastFmTextBox.Foreground = new SolidColorBrush(Colors.Red); ErrorConnectLastFmTextBox.Text = "It didn't worked. Please check your credentials"; Locator.SettingsVM.LastFmIsConnected = false; } }
public override async void Execute(object parameter) { if (Locator.MediaPlaybackViewModel.TrackCollection.IsRunning) { await Locator.MediaPlaybackViewModel.CleanViewModel(); } LogHelper.Log("PlayVideoCommand called"); VideoItem videoVm = null; if (parameter is ItemClickEventArgs) { ItemClickEventArgs args = parameter as ItemClickEventArgs; videoVm = args.ClickedItem as VideoItem; } else if (parameter is VideoItem) { videoVm = parameter as VideoItem; } // If the VM is null, we can't do anything. So just return. if (videoVm == null) { ToastHelper.Basic("Failed to load the selected video, the video view model is null."); LogHelper.Log("PLAYVIDEO: VideoVm is null, returning"); return; } LogHelper.Log("PLAYVIDEO: VideoVm is not null, continuing"); try { // If the video file is null (For example, the user deleted the video, and it's on // their favorites list.) We need to make sure the whole app does not crash. // TODO: If user selectes a video from their favoites, and it has been moved or deleted, we should ask them if we want to remove it from their list await videoVm.Play(); } catch (System.Exception) { // TODO: Enhance error handling // TODO: Remove hardcoded English ToastHelper.Basic("Failed to load the selected video"); return; } try { Locator.NavigationService.Go(VLCPage.VideoPlayerPage); LogHelper.Log("PLAYVIDEO: Navigating to VideoPlayerPage"); } catch { // TODO: Enhance error handling // TODO: Remove hardcoded English ToastHelper.Basic(string.Format("Failed to navigate to video player page.")); LogHelper.Log("PLAYVIDEO: failed to navigate to video player page."); } }
public bool AddAlbumToPlaylist(object args) { if (Locator.MusicLibraryVM.CurrentTrackCollection == null) { ToastHelper.Basic(Strings.HaveToSelectPlaylist, false, "selectplaylist"); return(false); } Locator.MusicLibraryVM.AddToPlaylistCommand.Execute(Locator.MusicLibraryVM.CurrentAlbum); return(true); }
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); } })); }
public override async void Execute(object parameter) { LogHelper.Log("PlayVideoCommand called"); VideoItem videoVm = null; if (parameter is ItemClickEventArgs) { ItemClickEventArgs args = parameter as ItemClickEventArgs; videoVm = args.ClickedItem as VideoItem; } else if (parameter is VideoItem) { videoVm = parameter as VideoItem; } // If the VM is null, we can't do anything. So just return. if (videoVm == null) { #if DEBUG ToastHelper.Basic("Failed to load the selected video, the video view model is null."); #endif LogHelper.Log("PLAYVIDEO: VideoVm is null, returning"); return; } LogHelper.Log("PLAYVIDEO: VideoVm is not null, continuing"); try { // If the video file is null (For example, the user deleted the video, and it's on // their favorites list.) We need to make sure the whole app does not crash. // TODO: If user selectes a video from their favoites, and it has been moved or deleted, we should ask them if we want to remove it from their list await Locator.PlaybackService.SetPlaylist(new List <IMediaItem> { videoVm }); } catch (System.Exception) { // TODO: Enhance error handling // TODO: Remove hardcoded English ToastHelper.Basic(Strings.FailOpenVideo); return; } }
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 AddToPlaylist(AlbumItem albumItem) { if (Locator.MusicLibraryVM.CurrentTrackCollection == null) { return; } var playlistId = Locator.MusicLibraryVM.CurrentTrackCollection.Id; Locator.MusicLibraryVM.CurrentTrackCollection.Playlist.AddRange(albumItem.Tracks); foreach (TrackItem trackItem in albumItem.Tracks) { await tracklistItemRepository.Add(new TracklistItem() { TrackId = trackItem.Id, TrackCollectionId = playlistId, }).ConfigureAwait(false); } ToastHelper.Basic(string.Format(Strings.TrackAddedToYourPlaylist, albumItem.Name), false, string.Empty, "playlistview"); }
public static void AddAlbumToPlaylist(object args) { if (Locator.MusicLibraryVM.CurrentTrackCollection == null) { #if WINDOWS_PHONE_APP if (args is ContentDialogButtonClickEventArgs) { ((ContentDialogButtonClickEventArgs)args).Cancel = true; } #endif ToastHelper.Basic(Strings.HaveToSelectPlaylist, false, "selectplaylist"); return; } #if WINDOWS_APP var flyout = ((AddAlbumToPlaylistBase)args).GetFirstDescendantOfType <SettingsFlyout>(); flyout?.Hide(); #endif Locator.MusicLibraryVM.AddToPlaylistCommand.Execute(Locator.MusicLibraryVM.CurrentAlbum); }
public static async Task AddToPlaylist(AlbumItem albumItem) { if (Locator.MusicLibraryVM.CurrentTrackCollection == null) { return; } var playlistId = Locator.MusicLibraryVM.CurrentTrackCollection.Id; foreach (TrackItem trackItem in albumItem.Tracks) { Locator.MusicLibraryVM.CurrentTrackCollection.Playlist.Add(trackItem); await Locator.MusicLibraryVM.TracklistItemRepository.Add(new TracklistItem() { TrackId = trackItem.Id, TrackCollectionId = playlistId, }); } ToastHelper.Basic(string.Format(Strings.TrackAddedToYourPlaylist, albumItem.Name)); }
public async Task AddToPlaylist(ArtistItem artistItem) { if (Locator.MusicLibraryVM.CurrentTrackCollection == null) { return; } var playlistId = Locator.MusicLibraryVM.CurrentTrackCollection.Id; var songs = Locator.MediaLibrary.LoadTracksByArtistId(artistItem.Id); await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => Locator.MusicLibraryVM.CurrentTrackCollection.Playlist.AddRange(songs)); foreach (TrackItem trackItem in songs) { await tracklistItemRepository.Add(new TracklistItem() { TrackId = trackItem.Id, TrackCollectionId = playlistId, }); } ToastHelper.Basic(string.Format(Strings.TrackAddedToYourPlaylist, artistItem.Name), false, string.Empty, "playlistview"); }
public static async Task AddNewPlaylist(string trackCollectionName) { if (string.IsNullOrEmpty(trackCollectionName)) { return; } TrackCollection trackCollection = null; trackCollection = await Locator.MusicLibraryVM.TrackCollectionRepository.LoadFromName(trackCollectionName); if (trackCollection != null) { await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => ToastHelper.Basic(Strings.PlaylistAlreadyExists)); } else { trackCollection = new TrackCollection(); trackCollection.Name = trackCollectionName; await Locator.MusicLibraryVM.TrackCollectionRepository.Add(trackCollection); await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Locator.MusicLibraryVM.TrackCollections.Add(trackCollection)); } }
public async Task AddToPlaylist(TrackItem trackItem, bool displayToastNotif = true) { if (Locator.MusicLibraryVM.CurrentTrackCollection == null) { return; } if (Locator.MusicLibraryVM.CurrentTrackCollection.Playlist.Contains(trackItem)) { ToastHelper.Basic(Strings.TrackAlreadyExistsInPlaylist); return; } Locator.MusicLibraryVM.CurrentTrackCollection.Playlist.Add(trackItem); await tracklistItemRepository.Add(new TracklistItem() { TrackId = trackItem.Id, TrackCollectionId = Locator.MusicLibraryVM.CurrentTrackCollection.Id, }); if (displayToastNotif) { ToastHelper.Basic(string.Format(Strings.TrackAddedToYourPlaylist, trackItem.Name), false, string.Empty, "playlistview"); } }
public async Task SendFeedbackItem(Feedback fb, bool sendLogs) { try { var result = await LogHelper.SendFeedback(fb, sendLogs); await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, async() => { if (result.EnsureSuccessStatusCode().IsSuccessStatusCode) { Locator.NavigationService.Go(VLCPage.SettingsPage); ToastHelper.Basic(Utils.Strings.FeedbackThankYou); } else { StatusTextBox.Text = Utils.Strings.ErrorSendingFeedback; ProgressRing.IsActive = false; #if DEBUG var md = new MessageDialog(result.ReasonPhrase + " - " + result.Content + " - " + result.StatusCode, "Bug in the Request"); await md.ShowQueuedAsync(); #endif } }); } catch (Exception e) { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, async() => { StatusTextBox.Text = Utils.Strings.ErrorSendingFeedback; ProgressRing.IsActive = false; #if DEBUG var md = new MessageDialog(e.ToString(), "Bug"); await md.ShowQueuedAsync(); #endif }); } }
public override async void Execute(object parameter) { var mrl = parameter as string; if (string.IsNullOrEmpty(mrl)) { ToastHelper.Basic("Please enter a valid URL."); return; } mrl = mrl.Trim(); //TODO: pass MRL to vlc try { var stream = new StreamMedia(mrl); await Locator.MediaPlaybackViewModel.SetMedia(stream); } catch (Exception ex) { ExceptionHelper.CreateMemorizedException("PlayNetworkMRLCommand.Execute", ex); return; } Locator.NavigationService.Go(VLCPage.VideoPlayerPage); Locator.MainVM.CloseStreamFlyout(); }
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); } })); }
private void Notify(string gamepadState) { ToastHelper.Basic(gamepadState); }
private async Task HandleProtocolActivation(IActivatedEventArgs args) { var protocolArgs = (ProtocolActivatedEventArgs)args; var uri = protocolArgs.Uri; if (string.IsNullOrEmpty(uri.Query)) { return; } WwwFormUrlDecoder decoder = new WwwFormUrlDecoder(uri.Query); switch (uri.Host) { case "goto": if (decoder[0]?.Name == "page") { if (decoder[0]?.Value == VLCPage.SettingsPageUI.ToString()) { Locator.NavigationService.Go(VLCPage.SettingsPageUI); } } break; case "openstream": // do stuff if (decoder[0]?.Name == "from") { switch (decoder[0]?.Value) { case "clipboard": await Task.Delay(1000); var dataPackage = Clipboard.GetContent(); Uri url = null; if (dataPackage.Contains(StandardDataFormats.ApplicationLink)) { url = await dataPackage.GetApplicationLinkAsync(); } else if (dataPackage.Contains(StandardDataFormats.WebLink)) { url = await dataPackage.GetWebLinkAsync(); } else if (dataPackage.Contains(StandardDataFormats.Text)) { url = new Uri(await dataPackage.GetTextAsync()); } if (url != null) { await Locator.MediaPlaybackViewModel.PlayStream(url.AbsoluteUri); } break; case "useraction": Locator.MainVM.GoToStreamPanel.Execute(null); break; case "url": if (decoder[1]?.Name == "url") { StorageFile subsFd = null; try { var subsFrom = decoder.Where((item, index) => item.Name == "subs_from").FirstOrDefault(); var subsValue = decoder.Where((item, index) => item.Name == "subs").FirstOrDefault(); if (!(subsFrom == default(IWwwFormUrlDecoderEntry) && subsValue == default(IWwwFormUrlDecoderEntry))) { switch (subsFrom.Value) { case "path": //this StorageFile is like a File Descriptor from Unix subsFd = await StorageFile.GetFileFromPathAsync(subsValue.Value); if (subsFd == null) { ToastHelper.Basic("Failed to Load Subtitles: Couln´t find the file."); } else if (!StorageApplicationPermissions.FutureAccessList.CheckAccess(subsFd)) { StorageApplicationPermissions.FutureAccessList.Add(subsFd); } break; case "url": using (var httpClient = new System.Net.Http.HttpClient()) { var subsContent = await httpClient.GetStringAsync(subsValue.Value); subsFd = await ApplicationData.Current.LocalFolder.CreateFileAsync(subsContent.GetHashCode().ToString(), CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(subsFd, subsContent); } break; case "picker": var openPicker = new FileOpenPicker(); openPicker.FileTypeFilter.Add(".srt"); openPicker.FileTypeFilter.Add(".txt"); openPicker.SuggestedStartLocation = PickerLocationId.Downloads; subsFd = await openPicker.PickSingleFileAsync(); break; } } } //StorageFile.GetFileFromPath or CreateFileAsync failed catch (UnauthorizedAccessException) { ToastHelper.Basic("Failed to Load Subtitles: Access Denied to the file."); } //HttpClient usually fails with an AggregateException instead of WebException or HttpRequest...Exception catch (AggregateException) { ToastHelper.Basic("Failed to Load Subtitles: Problems downloading the subtitles"); } //HttpClient fails with a WebException when there´s no connectivity catch (System.Net.WebException) { ToastHelper.Basic("Failed to Load Subtitles: No Connectivity"); } catch (Exception ex) { ToastHelper.Basic("Failed to Load Subtitles: " + ex.GetType().ToString()); } await Locator.MediaPlaybackViewModel.PlayStream(decoder[1].Value); if (subsFd != null) { ToastHelper.Basic("Subtitles Loaded Successfully"); Locator.MediaPlaybackViewModel.OpenSubtitleCommand.Execute(subsFd); } } break; } } break; } }
public async Task InitializePlayback(IVLCMedia media, bool autoPlay) { // First set the player engine // For videos AND music, we have to try first with Microsoft own player // Then we register to Failed callback. If it doesn't work, we set ForceVlcLib to true if (UseVlcLib) { _playerEngine = PlayerEngine.VLC; } else { var path = ""; if (!string.IsNullOrEmpty(media.Path)) { path = Path.GetExtension(media.Path); } else if (media.File != null) { path = media.File.FileType; } if (media is TrackItem) { if (VLCFileExtensions.MFSupported.Contains(path.ToLower())) { #if WINDOWS_PHONE_APP _playerEngine = PlayerEngine.BackgroundMFPlayer; #else _playerEngine = PlayerEngine.MediaFoundation; #endif } else { ToastHelper.Basic("This file might not play in background", false, "background"); _playerEngine = PlayerEngine.VLC; _mediaService.Stop(); } } else { // if it's a Video (Streams are always played with UseVlcLib flag). on WP we need smooth playback so using MediaFoundation as much as we can. #if WINDOWS_PHONE_APP _playerEngine = VLCFileExtensions.MFSupported.Contains(path.ToLower()) ? PlayerEngine.MediaFoundation : PlayerEngine.VLC; #else _playerEngine = PlayerEngine.VLC; #endif } } // Now, ensure the chosen Player is ready to play something await Locator.MediaPlaybackViewModel._mediaService.PlayerInstanceReady.Task; _mediaService.MediaFailed += _mediaService_MediaFailed; _mediaService.StatusChanged += PlayerStateChanged; _mediaService.TimeChanged += UpdateTime; // Send the media we want to play await _mediaService.SetMediaFile(media); _mediaService.OnLengthChanged += OnLengthChanged; _mediaService.OnStopped += OnStopped; _mediaService.OnEndReached += OnEndReached; _mediaService.OnBuffering += MediaServiceOnOnBuffering; switch (_playerEngine) { case PlayerEngine.VLC: var vlcService = (VLCService)_mediaService; if (vlcService.MediaPlayer == null) { return; } var em = vlcService.MediaPlayer.eventManager(); em.OnTrackAdded += Locator.MediaPlaybackViewModel.OnTrackAdded; em.OnTrackDeleted += Locator.MediaPlaybackViewModel.OnTrackDeleted; if (!autoPlay) { return; } vlcService.Play(); break; case PlayerEngine.MediaFoundation: var mfService = (MFService)_mediaService; if (mfService == null) { return; } if (!autoPlay) { return; } _mediaService.Play(); break; case PlayerEngine.BackgroundMFPlayer: if (!autoPlay) { return; } _mediaService.Play(CurrentMedia.Id); break; default: throw new ArgumentOutOfRangeException(); } await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => SpeedRate = 100); }
public async Task <PlaylistItem> AddNewPlaylist(string trackCollectionName) { if (string.IsNullOrEmpty(trackCollectionName)) { return(null); } PlaylistItem trackCollection = null; trackCollection = await trackCollectionRepository.LoadFromName(trackCollectionName); if (trackCollection != null) { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => ToastHelper.Basic(Strings.PlaylistAlreadyExists)); } else { trackCollection = new PlaylistItem(); trackCollection.Name = trackCollectionName; await trackCollectionRepository.Add(trackCollection); TrackCollections.Add(trackCollection); } return(trackCollection); }