示例#1
0
        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 SharedLogic.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;
        }
示例#2
0
        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 SharedLogic.CreateMediafile(file, true);

                if (Player.PlayerState == PlayerState.Paused || Player.PlayerState == PlayerState.Stopped)
                {
                    await Load(mp3File);
                }
                else
                {
                    await Load(mp3File, true);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Adds storage files into library.
        /// </summary>
        /// <param name="files">List containing StorageFile(s).</param>
        /// <returns></returns>
        public async static Task AddStorageFilesToLibraryAsync(IEnumerable <StorageFile> files)
        {
            foreach (var file in files)
            {
                Mediafile mp3file = null;
                int       index   = -1;
                if (file != null)
                {
                    if (TracksCollection.Elements.Any(t => t.Path == file.Path))
                    {
                        index = TracksCollection.Elements.IndexOf(TracksCollection.Elements.First(t => t.Path == file.Path));
                        RemoveMediafile(TracksCollection.Elements.First(t => t.Path == file.Path));
                    }
                    //this methods notifies the Player that one song is loaded. We use both 'count' and 'i' variable here to report current progress.
                    await NotificationManager.ShowMessageAsync(" Song(s) Loaded");

                    await Task.Run(async() =>
                    {
                        //here we load into 'mp3file' variable our processed Song. This is a long process, loading all the properties and the album art.
                        mp3file = await SharedLogic.CreateMediafile(file, false); //the core of the whole method.
                        await SaveSingleFileAlbumArtAsync(mp3file, file).ConfigureAwait(false);
                    });

                    AddMediafile(mp3file, index);
                }
            }
        }
示例#4
0
        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 SharedLogic.CreateMediafile(accessFile); //prepare Mediafile

                                await SettingsViewModel.SaveSingleFileAlbumArtAsync(mp3File, accessFile);
                                playlistSongs.Add(mp3File);
                                StorageApplicationPermissions.FutureAccessList.Remove(token);
                            }
                            catch
                            {
                                failedFiles++;
                            }
                        });
                    }
                }
                return(playlistSongs);
            }
        }
示例#5
0
        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 SharedLogic.CreateMediafile((StorageFile)await change.GetStorageItemAsync());

                    newFile.FolderPath = Path.GetDirectoryName(newFile.Path);
                    if (SharedLogic.AddMediafile(newFile))
                    {
                        await SharedLogic.NotificationManager.ShowMessageAsync(string.Format("Mediafile Added. File Path: {0}", newFile.Path), 5);
                    }
                }
            }
        }
示例#6
0
        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 SharedLogic.CreateMediafile((StorageFile)await change.GetStorageItemAsync());

                    createdItem.Id = id;
                    if (await LibraryService.UpdateMediafile(createdItem))
                    {
                        await SharedLogic.NotificationManager.ShowMessageAsync(string.Format("Mediafile Updated. File Path: {0}", createdItem.Path), 5);
                    }
                }
                else
                {
                    await AddNewItem(change);
                }
            }
        }
示例#7
0
        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 SharedLogic.CreateMediafile(accessFile); //prepare Mediafile
                            await SettingsViewModel.SaveSingleFileAlbumArtAsync(mp3File, accessFile);

                            playlistSongs.Add(mp3File);
                            StorageApplicationPermissions.FutureAccessList.Remove(token);
                        }
                        catch
                        {
                            failedFiles++;
                        }
                    });
                }
                return(playlistSongs);
            }
        }
示例#8
0
        public async Task LoadPlaylist(StorageFile file)
        {
            Playlist playlist = new Playlist {
                Name = file.DisplayName
            };

            using (var streamReader = new StreamReader(await file.OpenStreamForReadAsync()))
            {
                PlaylistService service = new PlaylistService(new KeyValueStoreDatabaseService(SharedLogic.DatabasePath, "", ""));
                await service.AddPlaylistAsync(playlist);

                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 SharedLogic.CreateMediafile(accessFile); //prepare Mediafile
                                await SettingsViewModel.SaveSingleFileAlbumArtAsync(mp3File, accessFile);
                                await SharedLogic.NotificationManager.ShowMessageAsync(index + " songs sucessfully added into playlist: " + file.DisplayName);
                                playlistSongs.Add(mp3File);
                                StorageApplicationPermissions.FutureAccessList.Remove(token);
                            }
                            catch
                            {
                                failedFiles++;
                            }
                        });
                    }
                    await service.InsertTracksAsync(playlistSongs, playlist);

                    string message = string.Format("Playlist \"{3}\" successfully imported! Total Songs: {0} Failed: {1} Succeeded: {2}", index, failedFiles, index - failedFiles, file.DisplayName);
                    await SharedLogic.NotificationManager.ShowMessageAsync(message);
                }
            }
        }
示例#9
0
        public async Task LoadPlaylist(StorageFile file)
        {
            //Core.CoreMethods.LibVM.Database.CreatePlaylistDB(file.DisplayName);
            //Dictionary<Playlist, IEnumerable<Mediafile>> PlaylistDict = new Dictionary<Models.Playlist, IEnumerable<Mediafile>>();
            Playlist playlist = new Playlist {
                Name = file.DisplayName
            };

            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>();
                PlaylistService  service       = new PlaylistService(new KeyValueStoreDatabaseService(SharedLogic.DatabasePath, "", ""));
                await service.AddPlaylistAsync(playlist);

                while ((line = reader.ReadLine()) != null)
                {
                    lines.Add(line);
                    nr++;
                    if (line == "[playlist]")
                    {
                        hdr = true;
                    }
                    else if (!hdr)
                    {
                        return;
                    }
                    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 SharedLogic.CreateMediafile(accessFile); //prepare Mediafile
                            await SettingsViewModel.SaveSingleFileAlbumArtAsync(mp3File, accessFile);

                            await SharedLogic.NotificationManager.ShowMessageAsync(i + " of " + noe + " songs added into playlist: " + file.DisplayName);
                            playlistSongs.Add(mp3File);
                            StorageApplicationPermissions.FutureAccessList.Remove(token);
                        }
                        catch
                        {
                            failedFiles++;
                        }
                    });

                    await service.InsertTracksAsync(playlistSongs, playlist);
                }
                string message = string.Format("Playlist \"{3}\" successfully imported! Total Songs: {0} Failed: {1} Succeeded: {2}", count, failedFiles, count - failedFiles, file.DisplayName);
                await SharedLogic.NotificationManager.ShowMessageAsync(message);
            }
        }