void UpdateInfo() { string path = binding.GetAbsolutePath(); try { var fs = new FileStream(path, FileMode.Open, FileAccess.Read); var reader = new BinaryReader(fs); if (reader.ReadUInt32() != 0x46464952) // "RIFF" { throw new Exception(); } reader.BaseStream.Seek(4, SeekOrigin.Current); if (reader.ReadUInt32() != 0x45564157) // "WAVE" { throw new Exception(); } ushort channels = 1; uint sampleRate = 44100; uint bytePerSec = sampleRate * 2; while (true) { uint chunk = reader.ReadUInt32(); uint chunkSize = reader.ReadUInt32(); if (chunk == 0x20746D66) // "fmt " { reader.BaseStream.Seek(2, SeekOrigin.Current); channels = reader.ReadUInt16(); sampleRate = reader.ReadUInt32(); bytePerSec = reader.ReadUInt32(); reader.BaseStream.Seek(-12, SeekOrigin.Current); } else if (chunk == 0x61746164) // "data" { ulong time = (ulong)chunkSize * 1000 / bytePerSec; lbl_info1.Text = System.String.Format("[Format] {0}ch {1}Hz", channels, sampleRate); lbl_info2.Text = System.String.Format("[TotalTime] {0:00}:{1:00}.{2:00}", time / 1000 / 60, time / 1000 % 60, time % 1000 / 10); break; } reader.BaseStream.Seek(chunkSize, SeekOrigin.Current); } fs.Close(); fs.Dispose(); } catch (Exception e) { } }
void Read() { if (binding != null) { btn_load.Enabled = true; lbl_file.Text = binding.GetRelativePath(); if (lbl_file.Text.Length > 0) { UpdatePreview(binding.GetAbsolutePath()); } else { //this.Height = 20; } } else { btn_load.Enabled = false; lbl_file.Text = string.Empty; lbl_info.Text = string.Empty; pic_preview.Image = null; } }