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
        /// <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.");
            }
        }
        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");
        }