Exemple #1
0
        private Mp3OutputDto SetMp3OutputDto(string mp3Path)
        {
            var mp3OutputDto  = new Mp3OutputDto();
            var mp3Dir        = Path.GetDirectoryName(mp3Path);
            var mp3OutputFile = Path.GetFileName(mp3Path);

            mp3OutputDto.OutputDir         = Path.Combine(mp3Dir, Path.GetFileNameWithoutExtension(mp3Path));
            mp3OutputDto.Mp3OutputFileName = Path.Combine(mp3OutputDto.OutputDir, Path.ChangeExtension(mp3OutputFile, Postfix));

            return(mp3OutputDto);
        }
Exemple #2
0
        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();
                }
            }
        }