private async Task LaunchTheApp(bool disableConsumingTasks = false) { Dispatcher = Window.Current.Dispatcher; Window.Current.Content = new MainPage(); Window.Current.Activate(); await SplitShell.TemplateApplied.Task; SetLanguage(); SetShellDecoration(); await LoadLibraries(disableConsumingTasks).ConfigureAwait(false); await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => { Locator.NavigationService.Go(Locator.SettingsVM.HomePage); if (Locator.SettingsVM.MediaCenterMode) { Locator.NavigationService.Go(VLCPage.MainPageXBOX); } else { App.SplitShell.FooterContent = new CommandBarBottom(); } }).ConfigureAwait(false); }
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 bool IsPreviousPossible() { bool isPossible = (CurrentTrack > 0); DispatchHelper.Invoke(() => CanGoPrevious = isPossible); return(isPossible); }
private async void Albums_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { try { if (Locator.MediaLibrary.Albums?.Count == 0 || Locator.MediaLibrary.Albums?.Count == 1) { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => { OnPropertyChanged(nameof(IsMusicLibraryEmpty)); OnPropertyChanged(nameof(MusicLibraryEmptyVisible)); }); } if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems.Count > 0) { foreach (var newItem in e.NewItems) { var album = (AlbumItem)newItem; await InsertIntoGroupAlbum(album); } } else { await OrderAlbums(); } } catch { } }
async Task OrderTracks() { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => { OnPropertyChanged(nameof(GroupedTracks)); }); }
public async Task LoadTracks(IReadOnlyList <StorageFile> tracks) { if (tracks == null) { return; } int i = 0; foreach (var track in tracks) { i++; var trackItem = await GetInformationsFromMusicFile.GetTrackItemFromFile(track, Artist, Name, i, ArtistId, Id); var databaseTrack = await _trackDataRepository.LoadTrack(ArtistId, Id, trackItem.Name); if (databaseTrack == null) { await _trackDataRepository.Add(trackItem); Tracks.Add(trackItem); } await DispatchHelper.InvokeAsync(() => { Locator.MusicLibraryVM.Track.Add(trackItem); OnPropertyChanged("Track"); }); } }
public async void SetEqualizerUI(VLCEqualizer eq) { if (eq == null) { return; } await DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { for (int i = 0; i < eq.Amps.Count; i++) { var anim = new DoubleAnimation(); anim.Duration = TimeSpan.FromMilliseconds(600); anim.EasingFunction = new ExponentialEase() { EasingMode = EasingMode.EaseOut, Exponent = 3, }; anim.To = Convert.ToDouble(eq.Amps[i]); anim.EnableDependentAnimation = true; Storyboard.SetTarget(anim, RootGrid.Children[i]); Storyboard.SetTargetProperty(anim, nameof(Slider.Value)); var sb = new Storyboard(); sb.Children.Add(anim); sb.Begin(); } }); }
private async void NotifyCommandBarDisplayModeChanged() { await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => { OnPropertyChanged(nameof(CommandBarDisplayMode)); }); }
public override async void Execute(object parameter) { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => { Locator.NavigationService.Go(VLCPage.CreateNewPlaylistDialog); }); }
private async void _selectedTracks_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { await DispatchHelper.InvokeInUIThread(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { OnPropertyChanged(nameof(IsTracksSelectedVisibility)); }); }
private async void MediaControl_PlayPressed(object sender, object e) { await DispatchHelper.InvokeAsync(() => { Play(); }); }
private async void OnMediaTrackDeleted(TrackType type, int trackId) { if (type == TrackType.Video) { return; } await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => { ObservableCollection <DictionaryKeyValue> target; if (type == TrackType.Audio) { target = AudioTracks; OnPropertyChanged(nameof(CurrentAudioTrack)); } else { target = Subtitles; OnPropertyChanged(nameof(CurrentSubtitle)); } var res = target.FirstOrDefault((item) => item.Id == trackId); if (res != null) { target.Remove(res); } }); }
private async void Playback_MediaEndReach() { switch (PlaybackService.PlayingType) { case PlayingType.Music: break; case PlayingType.Video: await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Low, () => { if (Locator.VideoPlayerVm.CurrentVideo != null) { Locator.VideoPlayerVm.CurrentVideo.TimeWatchedSeconds = 0; } }); if (Locator.VideoPlayerVm.CurrentVideo != null) { Locator.MediaLibrary.UpdateVideo(Locator.VideoPlayerVm.CurrentVideo); } break; case PlayingType.NotPlaying: break; default: break; } }
async void OnSizeChanged(object sender, WindowSizeChangedEventArgs windowSizeChangedEventArgs) { await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => { OnPropertyChanged(nameof(MiniPlayerVisibilityMediaCenter)); }); }
private async void onDefaultAudioRenderDeviceChanged(object sender, DefaultAudioRenderDeviceChangedEventArgs args) { if (args.Role != AudioDeviceRole.Default || args.Id == AudioDeviceID) { return; } AudioDeviceID = args.Id; // If we don't have an instance yet, no need to fetch the audio client as it will be done upon // instance creation. if (Instance == null) { return; } await DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { // Always fetch the new audio client, as we always assign it when starting a new playback AudioClient = new AudioDeviceHandler(AudioDeviceID); // But if a playback is in progress, inform VLC backend that we changed device if (MediaPlayer != null) { MediaPlayer.outputDeviceSet(AudioClient.audioClient()); } }); }
private async void Playback_MediaSet(IMediaItem media) { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => { OnPropertyChanged(nameof(IsMiniPlayerVisible)); OnPropertyChanged(nameof(CurrentTrack)); }); if (!(media is TrackItem)) { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => { CurrentAlbum = null; CurrentArtist = null; }); return; } await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, async() => { await SetCurrentArtist(); await SetCurrentAlbum(); await UpdatePlayingUI(); await Scrobble(); await UpdateWindows8UI(); if (CurrentArtist != null) { CurrentArtist.PlayCount++; await Locator.MediaLibrary.Update(CurrentArtist); } }); }
async Task CleanupAndHide() { if (_mediaPlayer == null) { Hide(); return; } if (_mediaPlayer.isPlaying()) { _mediaPlayer.stop(); } await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => { ProgressRing.IsActive = false; ProgressRing.Visibility = Visibility.Collapsed; }); _mediaPlayer.eventManager().OnPositionChanged -= OnOnPositionChanged; _mediaPlayer.eventManager().OnEndReached -= OnOnEndReached; _mediaPlayer.eventManager().OnEncounteredError -= OnOnEncounteredError; Media.VlcMedia = null; _mediaPlayer = null; _instance = null; await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, Hide); }
public void InitializeVideoImage() { if (_videoImage != null) { return; } if (HasThumbnail || HasMoviePicture) { _videosImageLoadingState = LoadingState.Loaded; Task.Run(async() => { await DispatchHelper.InvokeInUIThreadHighPriority(async() => { VideoImage = await GetBitmap(); }); }); } else if (_videosImageLoadingState == LoadingState.NotLoaded) { _videosImageLoadingState = LoadingState.Loading; Locator.MediaLibrary.GenerateVideoThumbnailAsync(this); } }
public SpecialThanksViewModel() { var _ = ThreadPool.RunAsync(async aa => { List <Backer> backers = await ParseBackers(); var backerDictionary = new SortedDictionary <string, List <string> >(); foreach (Backer backer in backers) { if (!backerDictionary.ContainsKey(backer.Country)) { backerDictionary.Add(backer.Country, new List <string>()); } backerDictionary[backer.Country].Add(backer.Name); } var backerCountries = new ObservableCollection <BackerCountryViewModel>(); foreach (string countryName in backerDictionary.Keys) { if (!string.IsNullOrWhiteSpace(countryName)) { string flagPath = "ms-appx:///Assets/Flags/flag_of_" + countryName.Replace(" ", "_") + ".png"; var backerCountry = new BackerCountryViewModel(countryName, new Uri(flagPath)); backerCountry.BackerNames = new List <string>(backerDictionary[countryName]); backerCountries.Add(backerCountry); } } await DispatchHelper.InvokeAsync(() => BackerCountries = backerCountries); }); }
async Task Initialize() { if (storageItem != null) { var props = await storageItem.GetBasicPropertiesAsync(); var size = await storageItem.GetSizeAsync(); var sizeString = ""; if (size > 0) { sizeString = size.GetSizeString(); } name = storageItem.DisplayName; await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Low, () => { lastModified = props.DateModified.ToString("dd/MM/yyyy hh:mm"); sizeHumanizedString = sizeString; OnPropertyChanged(nameof(LastModified)); OnPropertyChanged(nameof(SizeHumanizedString)); OnPropertyChanged(nameof(SizeAvailable)); OnPropertyChanged(nameof(Name)); }); } else if (media != null) { this.name = media.meta(MediaMeta.Title); await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Low, () => { OnPropertyChanged(nameof(Name)); }); } }
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)); } }); }
public async Task OnNavigatedFrom() { ResetLibrary(); switch (_musicView) { case MusicView.Albums: if (Locator.MediaLibrary.Albums != null) { Locator.MediaLibrary.Albums.CollectionChanged -= Albums_CollectionChanged; Locator.MediaLibrary.Albums.Clear(); } RecommendedAlbums?.Clear(); await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => { GroupedAlbums = null; LoadingStateAlbums = LoadingState.NotLoaded; }); break; case MusicView.Artists: if (Locator.MediaLibrary.Artists != null) { Locator.MediaLibrary.Artists.CollectionChanged -= Artists_CollectionChanged; Locator.MediaLibrary.Artists.Clear(); } await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => { GroupedArtists = null; LoadingStateArtists = LoadingState.NotLoaded; }); break; case MusicView.Songs: if (Locator.MediaLibrary.Tracks != null) { Locator.MediaLibrary.Tracks.CollectionChanged -= Tracks_CollectionChanged; Locator.MediaLibrary.Tracks.Clear(); } await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => { GroupedTracks = null; LoadingStateTracks = LoadingState.NotLoaded; }); break; case MusicView.Playlists: break; default: break; } }
Task InitializeArtists() { return(Task.Run(async() => { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => { Locator.MainVM.InformationText = Strings.LoadingMusic; LoadingStateArtists = LoadingState.Loading; GroupedArtists = new ObservableCollection <GroupItemList <ArtistItem> >(); }); if (Locator.MediaLibrary.Artists != null) { Locator.MediaLibrary.Artists.CollectionChanged += Artists_CollectionChanged; } await Locator.MediaLibrary.LoadArtistsFromDatabase(); var recommendedArtists = await Locator.MediaLibrary.LoadRandomArtistsFromDatabase(); await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => { RecommendedArtists = recommendedArtists; Locator.MainVM.InformationText = String.Empty; LoadingStateArtists = LoadingState.Loaded; OnPropertyChanged(nameof(IsMusicLibraryEmpty)); OnPropertyChanged(nameof(MusicLibraryEmptyVisible)); }); })); }
static public async Task Handle <T>(ObservableCollection <T> collection, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Move || e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace) { LogHelper.Log("Unexpected collection change: " + e.Action); return; } await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => { switch (e.Action) { case System.Collections.Specialized.NotifyCollectionChangedAction.Add: foreach (T v in e.NewItems) { collection.Add(v); } break; case System.Collections.Specialized.NotifyCollectionChangedAction.Reset: collection.Clear(); break; case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: foreach (T v in e.OldItems) { collection.Remove(v); } break; } }); }
async Task InsertIntoGroupArtist(ArtistItem artist) { try { var supposedFirstChar = Strings.HumanizedArtistFirstLetter(artist.Name); var firstChar = GroupedArtists.FirstOrDefault(x => (string)x.Key == supposedFirstChar); if (firstChar == null) { var newChar = new GroupItemList <ArtistItem>(artist) { Key = supposedFirstChar }; if (GroupedArtists == null) { return; } int i = GroupedArtists.IndexOf(GroupedArtists.LastOrDefault(x => string.Compare((string)x.Key, (string)newChar.Key) < 0)); i++; await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => GroupedArtists.Insert(i, newChar)); } else { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => firstChar.Add(artist)); } } catch { } }
private async Task RedirectFromSecondaryTile(string args) { try { var query = ""; int id; if (args.Contains("Album")) { query = args.Replace("SecondaryTile-Album-", ""); id = int.Parse(query); await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => Locator.MusicLibraryVM.AlbumClickedCommand.Execute(id)); } else if (args.Contains("Artist")) { query = args.Replace("SecondaryTile-Artist-", ""); id = int.Parse(query); await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => Locator.MusicLibraryVM.ArtistClickedCommand.Execute(id)); } } catch (Exception e) { LogHelper.Log("Failed to open from secondary tile : " + e.ToString()); } }
private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args) { switch (Locator.SettingsVM.ExternalDeviceMode) { case ExternalDeviceMode.AskMe: await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, () => new ShowExternalDevicePage().Execute(args)); break; case ExternalDeviceMode.IndexMedias: await AskExternalDeviceIndexing(args.Id); break; case ExternalDeviceMode.SelectMedias: await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Normal, async() => { await AskContentToCopy(args.Id); }); break; case ExternalDeviceMode.DoNothing: break; default: throw new NotImplementedException(); } if (ExternalDeviceAdded != null) { await ExternalDeviceAdded(sender, args.Id); } }
public static async Task LoadImageToMemory(AlbumItem item) { /* * Normally, We would need more tight calls to try and make sure that the file * exists in our database. However, since this is on the UI thread, we can't do that. * Since binding images directly through XAML leads to blocked files when we * need to delete them, we have to load them up manually. This should be enough * of a check, for now, to make sure images load correctly. */ bool fileExists = item.IsPictureLoaded; try { if (fileExists) { await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Low, () => item.AlbumImage = new BitmapImage(new Uri(item.AlbumCoverFullUri))); } } catch (Exception) { LogHelper.Log("Error getting album picture : " + item.Name); } if (!fileExists) { try { await Locator.MediaLibrary.FetchAlbumCoverOrWaitAsync(item); } catch { } } }
public bool IsNextPossible() { bool isPossible = (TrackCollection.Count != 1) && (CurrentTrack < TrackCollection.Count - 1); DispatchHelper.Invoke(() => CanGoNext = isPossible); return(isPossible); }
async void UpdateTrack(IMediaItem media) { await DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => { if (Track == null) { return; } if (Locator.MediaPlaybackViewModel.PlaybackService.CurrentMedia == -1 || Locator.MediaPlaybackViewModel.PlaybackService.Playlist?.Count == 0) { return; } if (Track.IsCurrentPlaying()) { previousBrush = NameTextBlock.Foreground; NameTextBlock.Foreground = (Brush)App.Current.Resources["MainColor"]; } else { if (previousBrush != null) { NameTextBlock.Foreground = previousBrush; } } }); }