private void comboPlayList_SelectionChanged(object sender, SelectionChangedEventArgs e) { ClearErrorMessage(); if (comboPlayList.SelectedItem is Models.PlayList) { Models.PlayList p = (Models.PlayList)comboPlayList.SelectedItem; if (p != null) { if (!string.IsNullOrEmpty(p.ImportedPath)) { ViewModelLocator.Settings.CurrentPlayListPath = p.ImportedPath; ViewModelLocator.Settings.CurrentPlayListIndex = comboPlayList.SelectedIndex; ViewModelLocator.Settings.CurrentMediaPath = string.Empty; ViewModelLocator.Settings.CurrentMediaIndex = p.Index; } else if (!string.IsNullOrEmpty(p.Path)) { ViewModelLocator.Settings.CurrentPlayListPath = p.Path; ViewModelLocator.Settings.CurrentPlayListIndex = comboPlayList.SelectedIndex; ViewModelLocator.Settings.CurrentMediaPath = string.Empty; ViewModelLocator.Settings.CurrentMediaIndex = p.Index; } ImportButton.IsEnabled = (((p.bImported == false) && (!p.Path.StartsWith("ms-appx://"))) ? true : false); RemoveButton.IsEnabled = true; } } }
private bool SelectPlaylistWithName(string Name) { if (comboPlayList.Items.Count > 0) { RemoveButton.IsEnabled = true; int index = 0; foreach (var item in comboPlayList.Items) { if (item is Models.PlayList) { Models.PlayList p = item as Models.PlayList; if (p != null) { if (string.Equals(p.Name, Name)) { comboPlayList.SelectedIndex = index; return(true); } } } index++; } } return(false); }
private async void RemovePlaylist_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { ClearErrorMessage(); if (comboPlayList.SelectedItem is Models.PlayList) { ObservableCollection <Models.PlayList> pll = ViewModelLocator.Settings.PlayListList; if ((pll != null) && (comboPlayList.SelectedIndex < pll.Count)) { Models.PlayList p = comboPlayList.SelectedItem as Models.PlayList; if (p != null) { if (!string.IsNullOrEmpty(p.ImportedPath)) { bool b = await Helpers.StorageHelper.RemoveFile(p.ImportedPath); } } pll.RemoveAt(comboPlayList.SelectedIndex); } ViewModelLocator.Settings.PlayListList = pll; if (comboPlayList.Items.Count > 0) { RemoveButton.IsEnabled = true; comboPlayList.SelectedIndex = 0; } else { ImportButton.IsEnabled = false; RemoveButton.IsEnabled = false; } } }
public async Task UpdatePlayList(Models.PlayList playList) { if (playList == null) { throw new ArgumentNullException($"Invalid playlist"); } await _playLists.UpdatePlaylistAsync(playList); }
private async void ImportPlaylist_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { ClearErrorMessage(); if (comboPlayList.SelectedItem is Models.PlayList) { Models.PlayList p = comboPlayList.SelectedItem as Models.PlayList; if (p != null) { Windows.Storage.StorageFolder playlistFolder = await Helpers.StorageHelper.GetFolder("playlist"); if (playlistFolder == null) { playlistFolder = await Helpers.StorageHelper.CreateLocalFolder("playlist"); } if (playlistFolder != null) { string folderName = System.IO.Path.GetFileName(playlistFolder.Path); string fileName = System.IO.Path.GetFileName(p.Path); // Remove existing imported playlist if (!string.IsNullOrEmpty(p.ImportedPath)) { await Helpers.StorageHelper.RemoveFile(p.ImportedPath); } // Get a unique filename string destFileName = fileName; destFileName = await Helpers.StorageHelper.GetUniqueFileName(folderName, fileName); Windows.Storage.StorageFile importedPlaylistfile = await Helpers.StorageHelper.CopyFileToFolder(p.Path, folderName, destFileName); if (importedPlaylistfile != null) { p.ImportedPath = importedPlaylistfile.Path; ObservableCollection <Models.PlayList> pll = ViewModelLocator.Settings.PlayListList; if ((pll != null) && (comboPlayList.SelectedIndex < pll.Count)) { pll[comboPlayList.SelectedIndex] = p; ViewModelLocator.Settings.PlayListList = pll; if (!SelectPlaylistWithName(p.Name)) { ImportButton.IsEnabled = false; RemoveButton.IsEnabled = false; } } } } } } }
public async Task AddPlayListByUserId(long?userId, Models.PlayList playList) { if (playList == null) { throw new ArgumentNullException($"Invalid playlist"); } var user = _user.Get(userId); var userPlaylist = new UserPlayList { PlayList = playList, User = user }; await _playLists.AddPlaylistAsync(playList); await _userPlayList.AddUserPlayListAsync(userPlaylist); }
private void comboPlayList_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { RemoveButton.IsEnabled = false; ImportButton.IsEnabled = false; if (comboPlayList.Items.Count > 0) { ViewModels.ViewModel vm = this.DataContext as ViewModels.ViewModel; if (vm != null) { string PlaylistPath = vm.Settings.CurrentPlayListPath; int index = 0; foreach (var item in comboPlayList.Items) { if (item is Models.PlayList) { Models.PlayList p = item as Models.PlayList; if (p != null) { if (string.Equals(p.Path, PlaylistPath)) { comboPlayList.SelectedIndex = index; break; } if (string.Equals(p.ImportedPath, PlaylistPath)) { comboPlayList.SelectedIndex = index; break; } } } index++; } if (comboPlayList.SelectedIndex < 0) { comboPlayList.SelectedIndex = 0; } } } }
public async static System.Threading.Tasks.Task <Models.PlayList> GetNewPlaylist(string path) { MediaDataSource.Clear(); MediaDataGroup audio_video = await MediaDataSource.GetGroupAsync(path, "audio_video_picture"); if (audio_video != null) { Models.PlayList playlist = new Models.PlayList(path, audio_video.Title); if (playlist != null) { playlist.bImported = false; playlist.bLocalItem = false; playlist.bRemoteItem = false; playlist.Count = audio_video.Items.Count; foreach (var item in audio_video.Items) { if (!string.IsNullOrEmpty(item.PosterContent)) { if (item.PosterContent.StartsWith("http", StringComparison.OrdinalIgnoreCase)) { playlist.bRemoteItem = true; } if (item.PosterContent.StartsWith("ms-appx://", StringComparison.OrdinalIgnoreCase)) { playlist.bLocalItem = true; } if (item.PosterContent.StartsWith("file://", StringComparison.OrdinalIgnoreCase)) { playlist.bLocalItem = true; } } if (!string.IsNullOrEmpty(item.Content)) { if (item.Content.StartsWith("http", StringComparison.OrdinalIgnoreCase)) { playlist.bRemoteItem = true; } else if (item.Content.StartsWith("redirect://", StringComparison.OrdinalIgnoreCase)) { playlist.bRemoteItem = true; } else if (item.Content.StartsWith("redirects://", StringComparison.OrdinalIgnoreCase)) { playlist.bRemoteItem = true; } else if (item.Content.StartsWith("ms-appx://", StringComparison.OrdinalIgnoreCase)) { playlist.bLocalItem = true; } else if (item.Content.StartsWith("file://", StringComparison.OrdinalIgnoreCase)) { playlist.bLocalItem = true; } } } playlist.Index = 0; playlist.bAnalyzed = true; playlist.bImported = false; playlist.ImportedPath = string.Empty; MediaDataSource.Clear(); return(playlist); } } MediaDataSource.Clear(); return(null); }
private async void AddPlaylist_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { var filePicker = new Windows.Storage.Pickers.FileOpenPicker(); filePicker.FileTypeFilter.Add(".json"); filePicker.FileTypeFilter.Add(".tma"); filePicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; //filePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary; filePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.MusicLibrary; filePicker.SettingsIdentifier = "PlaylistPicker"; filePicker.CommitButtonText = "Add JSON or TMA (TestMEdiaApp) Playlist File to your list"; ClearErrorMessage(); var file = await filePicker.PickSingleFileAsync(); if (file != null) { string fileToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file); try { Shell.Current.DisplayWaitRing = true; //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 1); Models.PlayList playlist = await Models.PlayList.GetNewPlaylist(file.Path); if (playlist != null) { if (playlist.Count > 0) { if (!IsThePlaylistNameUsed(playlist.Name)) { ViewModels.ViewModel vm = this.DataContext as ViewModels.ViewModel; if (vm != null) { ObservableCollection <Models.PlayList> PlayListList = vm.Settings.PlayListList; PlayListList.Add(playlist); vm.Settings.PlayListList = PlayListList; if (!SelectPlaylistWithName(playlist.Name)) { ImportButton.IsEnabled = false; RemoveButton.IsEnabled = false; } } } else { SetErrorMessage("Playlist name already used"); } } else { SetErrorMessage("Playlist empty: 0 item"); } } else { SetErrorMessage("Error while parsing the playlist file"); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message); } finally { Shell.Current.DisplayWaitRing = false; //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 1); } } }