本文整理汇总了C#中NAudio.Wave.AudioFileReader.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# AudioFileReader.CopyTo方法的具体用法?C# AudioFileReader.CopyTo怎么用?C# AudioFileReader.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NAudio.Wave.AudioFileReader
的用法示例。
在下文中一共展示了AudioFileReader.CopyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertToMP3
public static void ConvertToMP3(string inFile, string outFile, int bitRate = 64)
{
using (var reader = new AudioFileReader(inFile))
{
using (var writer = new LameMP3FileWriter(outFile, reader.WaveFormat, bitRate))
reader.CopyTo(writer);
}
}
示例2: ProcessVideo
private void ProcessVideo(SelectableViewModel selectedItem)
{
var videoInfo = DownloadUrlResolver.GetDownloadUrls(selectedItem.URL); // The long part.
VideoInfo video = null;
int[] bitrate = {0}; // Another ugly hack.
foreach (
var _video in
videoInfo.Where(_video => _video.AudioExtension == ".aac")
.Where(_video => _video.AudioBitrate > bitrate[0]))
{
bitrate[0] = _video.AudioBitrate;
video = _video;
}
if (video != null && video.RequiresDecryption)
{
DownloadUrlResolver.DecryptDownloadUrl(video); // Some fancy shit I don't know what it does but it's in the example app so I added it here.
}
var localFile = Path.Combine($"{Settings.Default.dlDir}/{video?.Title + video?.AudioExtension}");
var videoDownloader = new VideoDownloader(video, localFile); // Prepare for video downloading.
Dispatcher.Invoke(() => selectedItem.Progress = ProgressBar.Update(0)); // Initialise our lovely progress bar.
videoDownloader.DownloadProgressChanged +=
(s, a) => Dispatcher.Invoke(() => { selectedItem.Progress = ProgressBar.Update(a.ProgressPercentage); });
try
{
videoDownloader.Execute();
}
catch (Exception ex)
{
if (ex.Message == "The given path's format is not supported.") // Title most probably contains some NTFS-incompatible chars.
{
MessageBox.Show("Invalid filename detected, please choose a new filename in the next window.",
"LeafyYT");
var dialog = new VistaSaveFileDialog
{
Title = @"LeafyYT",
CheckFileExists = true,
ValidateNames = true,
InitialDirectory = Settings.Default.dlDir,
AddExtension = true,
DefaultExt = ".aac"
};
dialog.ShowDialog();
// Should probably send this back into a method instead of creating new ones...
if (!string.IsNullOrEmpty(dialog.FileName))
{
localFile = Path.Combine($"{Settings.Default.dlDir}/{dialog.FileName + video?.AudioExtension}");
var videoDownloader2 = new VideoDownloader(video, localFile);
Dispatcher.Invoke(() => selectedItem.Progress = ProgressBar.Update(0));
videoDownloader2.DownloadProgressChanged +=
(s, a) =>
Dispatcher.Invoke(
() => { selectedItem.Progress = ProgressBar.Update(a.ProgressPercentage); });
try
{
videoDownloader2.Execute();
}
catch (Exception ex2)
{
MessageBox.Show($"EXCEPTION: {ex2.GetType()}: {ex2.Message}");
return;
}
}
}
else
{
MessageBox.Show($"EXCEPTION: {ex.GetType()}: {ex.Message}");
return;
}
}
Dispatcher.Invoke(() => { selectedItem.Progress = "Converting..."; });
var oldFile = localFile.Replace("/", "\\"); // LameWriter doesn't seem to like / in filePath.
var newFile = oldFile.Replace(".aac", "") + ".mp3"; // lol.
using (var reader = new AudioFileReader(oldFile))
{
if (video != null)
{
using (var writer = new LameMP3FileWriter(newFile, reader.WaveFormat, video.AudioBitrate))
{
reader.CopyTo(writer); // Convert aac to mp3 using some black magic shit.
}
}
}
File.Delete(localFile);
Dispatcher.Invoke(() => { selectedItem.Progress = "Finished"; }); // Tadaaaaaaaaaaaa.
}