bool IMusicfilesConverter.ConvertTomp3(IProgress<TrackConverted> iprogress, CancellationToken iCancellationToken, bool deleteIfSucceed) { if (!_Lame.EncoderExists) { throw new InvalidDataException("Lame encoder not found."); } double From = 0; double To = 0; int stream = Bass.BASS_StreamCreateFile(_FileName.ToBeConsidered, 0, 0, BASSFlag.BASS_STREAM_DECODE); double time = Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream)); Bass.BASS_StreamFree(stream); bool finalres = true; int Count = _Cues.Count; for (int i = 0; i < Count; i++) { if (iCancellationToken.IsCancellationRequested) break; TrackDescriptor Tr = _Cues[i]; if (i == 0) From = -1; else { From = Tr.CueIndex01.TotalSeconds; } if (i + 1 < Count) { TimeCueIndexer tci = _Cues[i + 1].CueIndex00 ?? _Cues[i + 1].CueIndex01; To = tci.TotalSeconds; } else { To = (long)time; } string OutPut = FileInternalToolBox.CreateNewAvailableName(_Output, String.Format("{0}-{1}", Tr.TrackNumber, Tr.Name).FormatFileName(150), FileServices.MP3); FileChecker Out = new FileChecker(OutPut, _TempDir); bool OK = BaseEncoder.EncodeFile(_FileName.ToBeConsidered, Out.ToBeConsidered, _Lame, null, false, false, true, From, To); if (OK) { if (File.Exists(Out.ToBeConsidered)) Out.Finalise(); else OK = false; } if (OK == false) finalres = false; Tr.Path = OutPut; double realfrom = (From == -1) ? 0 : From; Tr.Duration = TimeSpan.FromSeconds(To - realfrom); iprogress.SafeReport(new TrackConverted(Tr, OK)); } _FileName.Finalise(); if (finalres && deleteIfSucceed) File.Delete(_FileName.Desired); return finalres; }