An audio player able to play audio from several audio and video formats (mp3, wma, avi, mp4... etc.) using XAudio2 and MediaFoundation.
Beispiel #1
0
        private void EjectButton_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog { Title = "Select an audio file (wma, mp3, ...etc.) or video file..." };
            if (dialog.ShowDialog() == true)
            {
                lock (lockAudio)
                {
                    if (audioPlayer != null)
                    {
                        audioPlayer.Close();
                        audioPlayer = null;
                    }

                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }

                    // Ask the user for a video or audio file to play
                    fileStream = new NativeFileStream(dialog.FileName, NativeFileMode.Open, NativeFileAccess.Read);

                    audioPlayer = new AudioPlayer(xaudio2, fileStream);

                    FilePathTextBox.Text = dialog.FileName;
                    SoundProgressBar.Maximum = audioPlayer.Duration.TotalSeconds;
                    SoundProgressBar.Value = 0;

                    // Auto-play
                    audioPlayer.Play();
                }
            }
        }