/// <summary> /// Navigates to the Audio Player screen with the requested file a parameter. /// </summary> /// <param name="file">The file to be played.</param> public async Task PlayAudioFile(StorageFile file) { Locator.NavigationService.Go(VLCPage.MusicPlayerPage); var trackItem = await MusicLibraryManagement.GetTrackItemFromFile(file); await PlaylistHelper.PlayTrackFromFilePicker(trackItem); }
public override async void Execute(object parameter) { var items = (ObservableCollection <IStorageItem>)parameter; var files = new List <StorageFile>(); foreach (var item in items) { var file = item as StorageFile; if (file != null && VLCFileExtensions.Supported.Contains(file.FileType.ToLower())) { files.Add((StorageFile)item); } } var playlist = new ObservableCollection <IVLCMedia>(); foreach (var file in files) { if (VLCFileExtensions.AudioExtensions.Contains(file.FileType.ToLower())) { var trackItem = await MusicLibraryManagement.GetTrackItemFromFile(file); playlist.Add(trackItem); } else if (VLCFileExtensions.VideoExtensions.Contains(file.FileType.ToLower())) { var videoVm = new VideoItem(); await videoVm.Initialize(file); playlist.Add(videoVm); } } await PlaylistHelper.AddTrackCollectionToPlaylistAndPlay(playlist, true, 0); }
public async Task GetFavoriteAndRandomAlbums() { await MusicLibraryManagement.LoadFavoriteRandomAlbums(); await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { OnPropertyChanged("RandomAlbums"); OnPropertyChanged("FavoriteAlbums"); }); }
public override async void Execute(object parameter) { if (parameter is TrackItem) { await MusicLibraryManagement.AddToPlaylist(parameter as TrackItem); } else if (parameter is AlbumItem) { await MusicLibraryManagement.AddToPlaylist(parameter as AlbumItem); } }
public override async void Execute(object parameter) { var md = new MessageDialog("Your playlist will no longer be accessible", "Are you sure?"); md.Commands.Add(new UICommand("yes", async command => { await MusicLibraryManagement.DeletePlaylist(Locator.MusicLibraryVM.CurrentTrackCollection); Locator.NavigationService.GoBack_Specific(); })); md.Commands.Add(new UICommand("no")); await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => await md.ShowAsync()); }
public override async void Execute(object parameter) { foreach (var item in Locator.MusicLibraryVM.CurrentTrackCollection.SelectedTracks.ToList()) { Locator.MusicLibraryVM.CurrentTrackCollection.Remove(item); if (item is TrackItem) { await MusicLibraryManagement.DeletePlaylistTrack(item as TrackItem, Locator.MusicLibraryVM.CurrentTrackCollection); } } //Locator.MusicLibraryVM.CurrentTrackCollection.SelectedTracks.Clear(); }
private async Task LoadFromDatabase() { await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Artists.Clear(); Tracks.Clear(); }); await MusicLibraryManagement.LoadFromSQL(); await DispatchHelper.InvokeAsync(() => { IsMusicLibraryEmpty = !Artists.Any(); OnPropertyChanged("IsMusicLibraryEmpty"); }); }
public async Task PerformRoutineCheckIfNotBusy() { // Routine check to add new files if there are new ones if (!IsBusy) { await App.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { IsBusy = true; }); await MusicLibraryManagement.DoRoutineMusicLibraryCheck(); await App.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { IsBusy = false; }); } }
public static async Task LoadImageToMemory(ArtistItem 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) { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(item.Picture)); using (var stream = await file.OpenAsync(FileAccessMode.Read)) { await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var image = new BitmapImage(); image.SetSource(stream); item.ArtistImage = image; }); } } } catch (Exception ex) { LogHelper.Log("Error getting artist picture : " + item.Name); } // Failed to get the artist image or no cover image. So go online and check // for a new one. if (!fileExists) { await MusicLibraryManagement.FetchArtistPicOrWaitAsync(item); } }
public async Task StartIndexing() { _artistDatabase.Drop(); _trackDatabase.Drop(); _albumDatabase.Drop(); await DispatchHelper.InvokeAsync(() => { Locator.MainVM.InformationText = "Searching for music"; IsBusy = true; IsLoaded = false; OnPropertyChanged("IsBusy"); OnPropertyChanged("IsLoaded"); }); _artistDatabase = new ArtistDatabase(); _artistDatabase.Initialize(); _trackDatabase.Initialize(); _albumDatabase.Initialize(); await MusicLibraryManagement.DoRoutineMusicLibraryCheck(); await LoadFromDatabase(); await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { IsBusy = false; IsLoaded = true; IsMusicLibraryEmpty = false; OnPropertyChanged("Artists"); OnPropertyChanged("FavoriteAlbums"); OnPropertyChanged("IsBusy"); OnPropertyChanged("IsMusicLibraryEmpty"); OnPropertyChanged("IsLoaded"); LoadingState = LoadingState.Loaded; Locator.MainVM.InformationText = ""; }); await GetFavoriteAndRandomAlbums(); }
public async Task SetMedia(IVLCMedia media, bool forceVlcLib = false, bool autoPlay = true) { if (media == null) { throw new ArgumentNullException("media", "Media parameter is missing. Can't play anything"); } Stop(); UseVlcLib = true; // forceVlcLib; if (media is VideoItem) { await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { PlayingType = PlayingType.Video; IsStream = false; Locator.NavigationService.Go(VLCPage.VideoPlayerPage); }); var video = (VideoItem)media; await Locator.MediaPlaybackViewModel.InitializePlayback(video, autoPlay); if (video.TimeWatched != TimeSpan.FromSeconds(0)) { await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Locator.MediaPlaybackViewModel.Time = (Int64)video.TimeWatched.TotalMilliseconds); } await SetMediaTransportControlsInfo(string.IsNullOrEmpty(video.Name)? "Video" : video.Name); UpdateTileHelper.UpdateMediumTileWithVideoInfo(); } else if (media is TrackItem) { await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { IsStream = false; PlayingType = PlayingType.Music; }); var track = (TrackItem)media; StorageFile currentTrackFile; try { currentTrackFile = track.File ?? await StorageFile.GetFileFromPathAsync(track.Path); } catch (Exception exception) { await MusicLibraryManagement.RemoveTrackFromCollectionAndDatabase(track); await Task.Delay(500); if (TrackCollection.CanGoNext) { await PlayNext(); } else { await App.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => Locator.NavigationService.GoBack_Specific()); } return; } await Locator.MediaPlaybackViewModel.InitializePlayback(track, autoPlay); if (_playerEngine != PlayerEngine.BackgroundMFPlayer) { await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await Locator.MusicPlayerVM.SetCurrentArtist(); await Locator.MusicPlayerVM.SetCurrentAlbum(); await Locator.MusicPlayerVM.UpdatePlayingUI(); Locator.Slideshow.AddImg(Locator.MusicPlayerVM.CurrentArtist.Picture); #if WINDOWS_APP await Locator.MusicPlayerVM.UpdateWindows8UI(); await Locator.MusicPlayerVM.Scrobble(); #endif }); } ApplicationSettingsHelper.SaveSettingsValue(BackgroundAudioConstants.CurrentTrack, TrackCollection.CurrentTrack); } else if (media is StreamMedia) { UseVlcLib = true; await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Locator.VideoVm.CurrentVideo = null; Locator.MediaPlaybackViewModel.PlayingType = PlayingType.Video; IsStream = true; }); await Locator.MediaPlaybackViewModel.InitializePlayback(media, autoPlay); } }
private async void AddToCollection_Click(object sender, RoutedEventArgs e) { await MusicLibraryManagement.AddNewPlaylist(playlistName.Text); Locator.NavigationService.GoBack_HideFlyout(); }
private void AddToPlaylistButton_Click(object sender, RoutedEventArgs e) { MusicLibraryManagement.AddAlbumToPlaylist(null); Locator.NavigationService.GoBack_Specific(); }
private async void NewPlaylistButton_Click(object sender, RoutedEventArgs e) { await MusicLibraryManagement.AddNewPlaylist(playlistName.Text); }