private static void Main() { var mp3InputDto = new Mp3InputDto { BeginCut = 0, EndCut = 1, Mp3Path = @"D:\mp3\20191215_ori.mp3" }; var mp3Cutter = new Service.Mp3Cutter(); var mp3OutputDto = mp3Cutter.ExecuteCut(mp3InputDto); System.Console.WriteLine(mp3OutputDto.Mp3OutputFileName); }
public Mp3OutputDto ExecuteCut(Mp3InputDto mp3InputDto) { int totalFrameCount = GetTotalFrameCount(mp3InputDto.Mp3Path); int totalTimeLength = GetTotalTimeLength(mp3InputDto.Mp3Path); frameProSec = GetFrameProSec(totalFrameCount, totalTimeLength); var mp3OutputDto = this.SetMp3OutputDto(mp3InputDto.Mp3Path); Directory.CreateDirectory(mp3OutputDto.OutputDir); CuttingMp3(mp3InputDto, mp3OutputDto); return(mp3OutputDto); }
private Mp3InputDto CreateInput() { int beginHours = Int32.Parse(txtBeginHour.Text); int beginMinutes = Int32.Parse(txtBeginMinute.Text); int beginSeconds = Int32.Parse(txtBeginSecond.Text); int endHours = Int32.Parse(txtEndHour.Text); int endMinutes = Int32.Parse(txtEndMinute.Text); int endSeconds = Int32.Parse(txtEndSecond.Text); var mp3Input = new Mp3InputDto(); mp3Input.BeginCut = beginHours * 3600 + beginMinutes * 60 + beginSeconds; mp3Input.EndCut = endHours * 3600 + endMinutes * 60 + endSeconds; mp3Input.Mp3Path = txtMp3FileName.Text; return(mp3Input); }
private void CuttingMp3(Mp3InputDto mp3InputDto, Mp3OutputDto mp3OutputDto) { int beginCount = (int)Math.Round(mp3InputDto.BeginCut * frameProSec); int endCount = (int)Math.Round(mp3InputDto.EndCut * frameProSec); FileStream writer = null; Action createWriter = new Action(() => { writer = File.Create(mp3OutputDto.Mp3OutputFileName); }); int totalFrameCount = 0; using (var reader = new Mp3FileReader(mp3InputDto.Mp3Path)) { Mp3Frame frame; while ((frame = reader.ReadNextFrame()) != null) { if (writer == null) { createWriter(); } if (totalFrameCount > beginCount && totalFrameCount < endCount) { ++totalFrameCount; continue; } writer.Write(frame.RawData, 0, frame.RawData.Length); ++totalFrameCount; } if (writer != null) { writer.Dispose(); } } }