Example #1
0
        public async static Task <ICollection <MusicEntry> > GetAllMusicEntriesAsync()
        {
            var musicEntries = new List <MusicEntry>();

            if (!File.Exists(TEXT_FILE_NAME))
            {
                return(musicEntries);
            }
            var content = await FileHelper.ReadTextFileAsync(TEXT_FILE_NAME);

            var lines = content.Split('\r', '\n');

            foreach (var line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                var lineParts = line.Split(',');
                var music     = new MusicEntry
                {
                    MusicTitle    = lineParts[0],
                    Album         = lineParts[1],
                    Singer        = lineParts[2],
                    ReleaseDate   = lineParts[3],
                    ImageFilePath = lineParts[4],
                    MusicFilePath = lineParts[5]
                };
                musicEntries.Add(music);
            }
            return(musicEntries);
        }
 public void SaveMusic(MusicEntry music)
 {
     if (!listOfMusic.Contains(music))
     {
         listOfMusic.Add(music);
     }
 }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            // Save music file path and cover image file path in txt format and show "saved"
            // collect data from controls to music entry here


            var entry = new MusicEntry
            {
                MusicTitle    = EnterTitle.Text,
                Singer        = EnterSinger.Text,
                Album         = EnterAlbum.Text,
                ReleaseDate   = EnteryDate.Text,
                ImageFilePath = ImagePathString.Text,
                MusicFilePath = MusicPathString.Text
            };

            if (string.IsNullOrEmpty(entry.MusicTitle) || string.IsNullOrEmpty(entry.ImageFilePath) || string.IsNullOrEmpty(entry.MusicFilePath))
            {
                var dialog = new MessageDialog("Music Title, Image File and Music File are required.");
                dialog.ShowAsync();
                return;
            }
            MusicEntry.WriteMusicEntry(entry);

            _storage.SaveMusic(entry);

            MainPage.MusicEntries.Add(entry);

            this.Frame.Navigate(typeof(MainPage), entry);   // passing parameter to the target page
        }
Example #4
0
        public static void WriteMusicEntry(MusicEntry music)
        {
            var MusicEntryData = $"{music.MusicTitle},{music.MusicFilePath},{music.ImageFilePath}";

            //var MusicEntryData = $"{music.Album},{music.MusicFilePath},{music.MusicTitle},{music.ReleaseDate},{music.Singer},{music.ImageFilePath}";
            FileHelper.WriteTextFileAsync(TEXT_FILE_NAME, MusicEntryData);
        }
Example #5
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            _musicEntry = e.Parameter as MusicEntry;

            FileStream fs = new FileStream(_musicEntry.MusicFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);

            MP3MetafileReader(fs);

            BitmapImage image       = new BitmapImage();
            var         storageFile = await StorageFile.GetFileFromPathAsync(_musicEntry.ImageFilePath);

            using (Windows.Storage.Streams.IRandomAccessStream stream = await storageFile.OpenAsync(FileAccessMode.Read))
            {
                await image.SetSourceAsync(stream);
            }
            this.image.Source = image;
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            // collect data from controls to music entry here

            MusicEntry entry = new MusicEntry();

            entry.MusicTitle    = _mp3Title;
            entry.MusicFilePath = _mp3Path;
            entry.ImageFilePath = _imgPath;


//            this.Frame.Navigate(typeof(MainPage), entry);   // passing parameter to the target page


            /*
             * // Save music file path and cover image file path in txt format and show "saved"
             * // collect data from controls to music entry here
             *
             * var entry = new MusicEntry
             * {
             *  MusicTitle = EnterTitle.Text,
             *  Singer = EnterSinger.Text,
             *  Album = EnterAlbum.Text,
             *  ReleaseDate = EnterDate.Text,
             *  ImageFilePath = ImagePathString.Text,
             *  MusicFilePath = MusicPathString.Text
             * };
             * if (string.IsNullOrEmpty(entry.MusicTitle) || string.IsNullOrEmpty(entry.ImageFilePath) || string.IsNullOrEmpty(entry.MusicFilePath))
             * {
             *  var dialog = new MessageDialog("Music Title, Image File and Music File are required.");
             *  dialog.ShowAsync();
             *  return;
             * }
             */
            MusicEntry.WriteMusicEntry(entry);

            MainPage.MusicEntries.Add(entry);

            this.Frame.Navigate(typeof(MainPage), entry);   // passing parameter to the target page
        }