private void ExtractPcmInfoFromAudioFile() { var reader = new AudioFileReader(selectedFile); Log.Debug("Beginning extraction of audio data from " + reader.ToString()); bitsPerSample = reader.WaveFormat.BitsPerSample; channelCount = reader.WaveFormat.Channels; sampleRate = reader.WaveFormat.SampleRate; encodingType = reader.WaveFormat.Encoding.ToString();; bytesPerSample = (reader.WaveFormat.BitsPerSample / 8); var samples = reader.Length / (bytesPerSample); samplesTotal = (int)samples; audioFrames = samplesTotal / channelCount; UpdateAudioInfoOnForm(); ButtonPlayFile.Enabled = true; string audioDataToText = String.Format("BitsPerSample: {0}, ChannelCount: {1}, SampleRate: {2}, EncodingType{3}, BytesPerSample: {4}, AudioFrames: {5}", bitsPerSample, channelCount, sampleRate, encodingType, bytesPerSample, audioFrames); Log.Debug(audioDataToText); // PlaybackPcmAudio(reader); }
private void Play(string file) { if (state == State.NaN || state == State.Stop) { try { var t = new AudioFileReader(file).TotalTime; var time = Math.Floor(t.TotalSeconds); TimeTotal.Text = t.ToString(@"mm\:ss"); TimeSlider.Maximum = time; } catch (Exception e) { var mp3File = new Mp3(file); var t = mp3File.Audio.Duration; var time = Math.Floor(t.TotalSeconds); TimeTotal.Text = t.ToString(@"mm\:ss"); TimeSlider.Maximum = time; } TimeSlider.Value = 0; Player.Open(new Uri(file)); Player.SpeedRatio = 1; Player.MediaEnded += (o, e) => Stop(null, null); Timer.Interval = TimeSpan.FromSeconds(0.5); Timer.Tick += (o, e) => { TimeNow.Text = Player.Position.ToString(@"mm\:ss"); var now = Player.Position.TotalSeconds; PChange = true; TimeSlider.Value = now; PChange = false; }; Timer.Start(); Player.Play(); Player.Volume -= 0.02; Player.Volume += 0.02; state = State.Play; PausePlay.Content = "Пауза"; TimeNow.Text = "00:00"; } }