private async void HandleExecuteCmdMessage(Message message) { if (message.Payload == null) { return; } if (message.Payload is List <object> list) { double volume = 0; if ((double)list[3] == 50.0) { volume = RoamingSettingsHelper.GetSetting <double>("volume", 50.0); } else { volume = (double)list[3]; } await Load(await TagReaderHelper.CreateMediafile(list[0] as StorageFile), (bool)list[2], (double)list[1], volume); } else { GetType().GetTypeInfo().GetDeclaredMethod(message.Payload as string)?.Invoke(this, new object[] { }); } message.HandledStatus = MessageHandledStatus.HandledCompleted; }
private async void Open(object para) { FileOpenPicker openPicker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.MusicLibrary }; openPicker.FileTypeFilter.Add(".mp3"); openPicker.FileTypeFilter.Add(".wav"); openPicker.FileTypeFilter.Add(".ogg"); openPicker.FileTypeFilter.Add(".flac"); openPicker.FileTypeFilter.Add(".m4a"); openPicker.FileTypeFilter.Add(".aif"); openPicker.FileTypeFilter.Add(".wma"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { var mp3File = await TagReaderHelper.CreateMediafile(file, true); if (Player.PlayerState == PlayerState.Paused || Player.PlayerState == PlayerState.Stopped) { await Load(mp3File); } else { await Load(mp3File, true); } } }
private async void HandlePlaySongMessage(Message message) { if (message.Payload is List <object> obj) { message.HandledStatus = MessageHandledStatus.HandledCompleted; var file = obj[0] as Mediafile; var play = (bool)obj[1]; IsPlayingFromPlaylist = (bool)obj[2]; if (obj.Count > 3) { IsPlayingFromNetwork = (bool)obj[3]; } await Load(file, play); } else if (message.Payload is string path) { message.HandledStatus = MessageHandledStatus.HandledCompleted; var mediaFile = await TagReaderHelper.CreateMediafile(await StorageFile.GetFileFromPathAsync(path)); await Load(mediaFile, true); } else if (message.Payload is StorageFile file) { message.HandledStatus = MessageHandledStatus.HandledCompleted; await Load(await FromNetworkStorageFile(file).ConfigureAwait(false), true); } }
private async void Open(object para) { FileOpenPicker openPicker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.MusicLibrary }; openPicker.FileTypeFilter.Add(".mp3"); openPicker.FileTypeFilter.Add(".wav"); openPicker.FileTypeFilter.Add(".ogg"); openPicker.FileTypeFilter.Add(".flac"); openPicker.FileTypeFilter.Add(".m4a"); openPicker.FileTypeFilter.Add(".aif"); openPicker.FileTypeFilter.Add(".wma"); openPicker.FileTypeFilter.Add(".aac"); openPicker.FileTypeFilter.Add(".mp4"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file); var mp3File = await TagReaderHelper.CreateMediafile(file); if (SharedLogic.Instance.Player.PlayerState == PlayerState.Paused || SharedLogic.Instance.Player.PlayerState == PlayerState.Stopped) { await Load(mp3File); } else { await Load(mp3File, true); } } }
private async void HandleExecuteCmdMessage(Message message) { if (message.Payload == null) { return; } if (message.Payload is List <object> list) { double volume = 0; if ((double)list[3] == 50.0) { volume = SettingsHelper.GetLocalSetting <double>("volume", 50.0); } else { volume = (double)list[3]; } Mediafile libraryMediaFile = null; if (list[0] is IReadOnlyList <IStorageItem> files) { List <Mediafile> mediafileList = new List <Mediafile>(files.Count); foreach (IStorageItem item in files) { if (item.IsOfType(StorageItemTypes.File)) { mediafileList.Add(await TagReaderHelper.CreateMediafile(item as StorageFile)); } } NowPlayingQueue = new ThreadSafeObservableCollection <Mediafile>(); NowPlayingQueue.AddRange(mediafileList); libraryMediaFile = NowPlayingQueue[0]; } else { var id = SettingsHelper.GetLocalSetting <long>("NowPlayingID", 0L); libraryMediaFile = _service.GetMediafile(id); if (libraryMediaFile == null) { var path = SettingsHelper.GetLocalSetting <string>("path", null); if (path != null) { if (await Task.Run(() => File.Exists(path))) { libraryMediaFile = await TagReaderHelper.CreateMediafile(await StorageFile.GetFileFromPathAsync(path)); } } } } await Load(libraryMediaFile, (bool)list[2], (double)list[1], volume); } else { GetType().GetTypeInfo().GetDeclaredMethod(message.Payload as string)?.Invoke(this, new object[] { }); } message.HandledStatus = MessageHandledStatus.HandledCompleted; }
private async Task <Mediafile> FromNetworkStorageFile(StorageFile file) { var mediaFile = await TagReaderHelper.CreateMediafile(file); mediaFile.MediaLocation = MediaLocationType.Device; mediaFile.ByteArray = await(await file.OpenStreamForReadAsync()).ToByteArray(); return(mediaFile); }
public async Task <IEnumerable <Mediafile> > LoadPlaylist(StorageFile file) { using (var streamReader = new StreamReader(await file.OpenStreamForReadAsync())) { List <Mediafile> playlistSongs = new List <Mediafile>(); string line; int index = 0; int failedFiles = 0; bool ext = false; while ((line = streamReader.ReadLine()) != null) { if (line.ToLower() == "#extm3u") //m3u header { ext = true; } else if (ext && line.ToLower().StartsWith("#extinf:")) //extinfo of each song { continue; } else if (line.StartsWith("#") || line == "") //pass blank lines { continue; } else { await Task.Run(async() => { try { index++; FileInfo info = new FileInfo(file.Path); //get playlist file info to get directory path string path = line; if (!File.Exists(line) && line[1] != ':') // if file doesn't exist then perhaps the path is relative { path = info.DirectoryName + line; //add directory path to song path. } var accessFile = await StorageFile.GetFileFromPathAsync(path); var token = StorageApplicationPermissions.FutureAccessList.Add(accessFile); Mediafile mp3File = await TagReaderHelper.CreateMediafile(accessFile); //prepare Mediafile await SettingsViewModel.SaveSingleFileAlbumArtAsync(mp3File, accessFile); playlistSongs.Add(mp3File); StorageApplicationPermissions.FutureAccessList.Remove(token); } catch { failedFiles++; } }); } } return(playlistSongs); } }
public static async Task AddNewItem(this StorageLibraryChange change) { if (change.IsOfType(StorageItemTypes.File)) { if (await change.GetStorageItemAsync() == null) { return; } if (IsItemPotentialMediafile(await change.GetStorageItemAsync())) { var newFile = await TagReaderHelper.CreateMediafile((StorageFile)await change.GetStorageItemAsync()); newFile.FolderPath = Path.GetDirectoryName(newFile.Path); if (SharedLogic.Instance.AddMediafile(newFile)) { await SharedLogic.Instance.NotificationManager.ShowMessageAsync(string.Format("Mediafile Added. File Path: {0}", newFile.Path), 5); } } } }
public static async Task UpdateChangedItem(this StorageLibraryChange change, IEnumerable <Mediafile> Library, LibraryService LibraryService) { if (change.IsOfType(StorageItemTypes.File)) { if (IsItemInLibrary(change, Library, out Mediafile createdItem)) { var id = createdItem.Id; createdItem = await TagReaderHelper.CreateMediafile((StorageFile)await change.GetStorageItemAsync()); createdItem.Id = id; if (await LibraryService.UpdateMediafile(createdItem)) { await SharedLogic.Instance.NotificationManager.ShowMessageAsync(string.Format("Mediafile Updated. File Path: {0}", createdItem.Path), 5); } } else { await AddNewItem(change); } } }
private async void HandleExecuteCmdMessage(Message message) { if (message.Payload == null) { return; } if (message.Payload is List <object> list) { double volume = 0; if ((double)list[3] == 50.0) { volume = SettingsHelper.GetLocalSetting <double>("volume", 50.0); } else { volume = (double)list[3]; } Mediafile libraryMediaFile = null; if (list[0] is StorageFile file) { libraryMediaFile = await TagReaderHelper.CreateMediafile(file); } else { var id = SettingsHelper.GetLocalSetting <long>("NowPlayingID", 0); libraryMediaFile = _service.GetMediafile(id); } await Load(libraryMediaFile, (bool)list[2], (double)list[1], volume); } else { GetType().GetTypeInfo().GetDeclaredMethod(message.Payload as string)?.Invoke(this, new object[] { }); } message.HandledStatus = MessageHandledStatus.HandledCompleted; }
public async Task <IEnumerable <Mediafile> > LoadPlaylist(StorageFile file) { using (var reader = new StreamReader(await file.OpenStreamForReadAsync())) { bool hdr = false; //[playlist] header string version = ""; //pls version at the end int noe = 0; //numberofentries at the end. int nr = 0; int failedFiles = 0; //int count = 0; string line; //a single line in stream List <string> lines = new List <string>(); List <Mediafile> playlistSongs = new List <Mediafile>(); while ((line = reader.ReadLine()) != null) { lines.Add(line); nr++; if (line == "[playlist]") { hdr = true; } else if (!hdr) { return(null); } else if (line.ToLower().StartsWith("numberofentries=")) { noe = Convert.ToInt32(line.Split('=')[1]); } else if (line.ToLower().StartsWith("version=")) { version = line.Split('=')[1]; } } string[,] tracks = new string[noe, 3]; nr = 0; foreach (string l in lines) { var _l = l.ToLower(); if (_l.StartsWith("file") || _l.StartsWith("title") || _l.StartsWith("length")) { int tmp = 4; int index = 0; if (_l.StartsWith("title")) { tmp = 5; index = 1; } else if (_l.StartsWith("length")) { tmp = 6; index = 2; } string[] split = l.Split('='); int number = Convert.ToInt32(split[0].Substring(tmp)); if (number > noe) { continue; } tracks[number - 1, index] = split[1]; } //else if (!_l.StartsWith("numberofentries") && _l != "[playlist]" && !_l.StartsWith("version=")) //{ //} } for (int i = 0; i < noe; i++) { await Task.Run(async() => { try { string trackPath = tracks[i, 0]; FileInfo info = new FileInfo(file.Path); //get playlist file info to get directory path string path = trackPath; if (!File.Exists(trackPath) && line[1] != ':') // if file doesn't exist then perhaps the path is relative { path = info.DirectoryName + line; //add directory path to song path. } var accessFile = await StorageFile.GetFileFromPathAsync(path); var token = StorageApplicationPermissions.FutureAccessList.Add(accessFile); Mediafile mp3File = await TagReaderHelper.CreateMediafile(accessFile); //prepare Mediafile await SettingsViewModel.SaveSingleFileAlbumArtAsync(mp3File, accessFile); playlistSongs.Add(mp3File); StorageApplicationPermissions.FutureAccessList.Remove(token); } catch { failedFiles++; } }); } return(playlistSongs); } }