简体   繁体   English

NWaves Xamarin Android 不播放 wav 文件

[英]NWaves Xamarin Android not play wav file

        try
        {
            using (var stream = new FileStream(fistBank, FileMode.Open))
            {
                var waveFile = new WaveFile(stream);
                signal = waveFile[Channels.Left];
            }
        }
        catch(Exception ex)
        {
            Toast.MakeText(Application.Context, ex.ToString(), ToastLength.Short).Show();
        }

Added to the project, added permissions for reading files, I get the path to the file.添加到项目中,添加了读取文件的权限,我得到了文件的路径。 I press the button and silence... The file does not play... It does not even generate signals from examples我按下按钮并静音...文件不播放...它甚至不会从示例中生成信号

I check the wiki of NWaves.我查看了 NWaves 的 wiki。 Playing and recording work only on Windows, since they use winmm.dll and MCI commands.播放和录制仅适用于 Windows,因为它们使用 winmm.dll 和 MCI 命令。 You could use MediaPlayer in Xamarin.Android instead.您可以在 Xamarin.Android 中使用MediaPlayer

 string fileName = "WAV_1MG.wav";
            var player = new MediaPlayer();
            var fd = Application.Context.Assets.OpenFd(fileName);
            player.Prepared += (s, e) =>
            {
                player.Start();
            };
            player.SetDataSource(fd.FileDescriptor, fd.StartOffset, fd.Length);
            player.Prepare();

WAV_1MG.wav file is in the Android Assets folder with the AndroidAsset Build Action. WAV_1MG.wav文件位于带有AndroidAsset构建操作的 Android Assets文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM