当前位置: 首页>>代码示例>>C#>>正文


C# AudioFileReader.CopyTo方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:rayanc,项目名称:Pecuniaus,代码行数:9,代码来源:AudioHelper.cs

示例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.
        }
开发者ID:LeafyCoding,项目名称:YT_Downloader,代码行数:100,代码来源:MainWindow.xaml.cs


注:本文中的NAudio.Wave.AudioFileReader.CopyTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。