private async void LoadFolder_Click(object sender, RoutedEventArgs e)
        {
            VistaFolderBrowserDialog x = new VistaFolderBrowserDialog();

            x.Description = "burp";

            if (!x.ShowDialog().Value)
            {
                return;
            }
            AudioFiles.Clear();

            string [] fileEntries = Directory.GetFiles(x.SelectedPath);
            foreach (string fileName in fileEntries)
            {
                var fileInfo  = new FileInfo(fileName);
                var audioInfo = await AudioEncoder.GetInfo(fileInfo.FullName);

                if (audioInfo == null)
                {
                    continue;
                }

                var audioStream = audioInfo.AudioStreams.FirstOrDefault();

                if (audioStream == null)
                {
                    continue;
                }


                AudioFiles.Add(new AudioFile
                {
                    InputFile    = fileInfo,
                    FileName     = System.IO.Path.GetFileNameWithoutExtension(fileInfo.FullName),
                    SamplingRate = audioStream.SampleRate,
                    BitRate      = audioStream.Bitrate,
                    Duration     = audioStream.Duration.TotalSeconds
                });
            }

            OnPropertyChanged("AudioFiles");
        }
Exemplo n.º 2
0
        public void Add(AudioFile audioFile)
        {
            AudioFiles.Add(audioFile);

            // add artist to folder if we don't already have it
            if (!Artists.ContainsKey(audioFile.Artist))
            {
                Artists.Add(audioFile.Artist, new Artist(this, audioFile.Artist));
            }

            // add album to artist if we don't already have it
            if (!Artists[audioFile.Artist].Albums.ContainsKey(audioFile.Album))
            {
                Artists[audioFile.Artist].AddAlbum(audioFile.Album);
            }

            // add file to album
            Artists[audioFile.Artist].Albums[audioFile.Album].AddFile(audioFile);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a file to the playlist
        /// </summary>
        /// <param name="filePath"></param>
        public void AddFileToPlaylist(string filePath, int index)
        {
            // create audio file object
            AudioFile audioFile = MediaFile.GetMediaFileByFilename(filePath) as AudioFile;

            // if successful, add to collection
            if (audioFile != null)
            {
                // check if the file should be added to the end of the playlist or somewhere in the middle
                if (index < AudioFiles.Count)
                {
                    AudioFiles.Insert(index, audioFile);
                }
                else
                {
                    AudioFiles.Add(audioFile);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads local audio information.
        /// </summary>
        public void ReadAudioFileInfo()
        {
            AudioFiles.Clear();

            // Load the image which was filtered from isolated app storage.
            System.IO.IsolatedStorage.IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();

            try
            {
                string[] fileNames = myStore.GetFileNames();
                foreach (string s in fileNames)
                {
                    AudioFileModel audioFile = new AudioFileModel();
                    audioFile.FileName = s;
                    IsolatedStorageFileStream fileStream = myStore.OpenFile(s, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    audioFile.FileSize = "" + fileStream.Length + " bytes";

                    // Read sample rate and channel count
                    Encoding encoding = Encoding.UTF8;
                    byte[]   bytes    = new byte[4];

                    // channel count
                    fileStream.Seek(22, SeekOrigin.Begin);
                    fileStream.Read(bytes, 0, 2);
                    audioFile.ChannelCount = BitConverter.ToInt16(bytes, 0);

                    // sample rate
                    fileStream.Read(bytes, 0, 4);
                    audioFile.SampleRate = BitConverter.ToInt32(bytes, 0);

                    audioFile.FileLength = "" + fileStream.Length / (2 * audioFile.SampleRate * audioFile.ChannelCount) + " seconds";
                    AudioFiles.Add(audioFile);

                    fileStream.Dispose();
                }
            }
            catch
            {
                MessageBox.Show("Error while trying to read audio files.");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Recurse through folders, storing data read from files
        /// </summary>
        /// <param name="bw"></param>
        /// <param name="strPath"></param>
        /// <returns></returns>
        private Folder AddFolder(string path)
        {
            Folder f = new Folder(path);

            // do files
            string[] filenames = Directory.GetFiles(path);
            int      fileCount = 0;

            foreach (string file in filenames)
            {
                // TODO: Check for wrapper type for extension
                MediaFile mediaFile = MediaFile.GetMediaFileByFilename(file);

                if (mediaFile != null)
                {
                    fileCount++;

                    f.Files.Add(mediaFile);

                    if (mediaFile is AudioFile)
                    {
                        AudioFiles.Add((AudioFile)mediaFile);
                    }
                    // HANDLE OTHER TYPES

                    //// report number of files found
                    //bw.ReportProgress(0, iMediaFileCount);
                }
            }

            // recurse through child folders
            string[] directories = Directory.GetDirectories(path);
            foreach (string directory in directories)
            {
                f.Folders.Add(AddFolder(directory));
            }

            return(f);
        }
        private async void LoadFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog {
                Title = "Audiodatei auswählen", Multiselect = true
            };

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            AudioFiles.Clear();
            foreach (string fileName in openFileDialog.FileNames)
            {
                var fileInfo  = new FileInfo(fileName);
                var audioInfo = await AudioEncoder.GetInfo(fileInfo.FullName);

                var audioStream = audioInfo?.AudioStreams?.FirstOrDefault();

                if (audioStream == null)
                {
                    continue;
                }


                AudioFiles.Add(new AudioFile
                {
                    InputFile    = fileInfo,
                    FileName     = System.IO.Path.GetFileNameWithoutExtension(fileInfo.FullName),
                    SamplingRate = audioStream.SampleRate,
                    BitRate      = audioStream.Bitrate,
                    Duration     = audioStream.Duration.TotalSeconds
                });
            }

            OnPropertyChanged("AudioFiles");
        }