系统无法找到指定的文件错误,当我向Xamarin Forms项目添加声音文件时。

huangapple go评论70阅读模式
英文:

the system cannot find the file specified error when i add sound file to xamarin forms project

问题

I add this bip.wav file to Assets folder and i got this the system cannot find the file specified error.

我将bip.wav文件添加到Assets文件夹中,但出现了“系统找不到指定的文件”错误。

I delete the sound file then clean solution and rebuild solution. After all that processes my app works.

我删除了声音文件,然后清理解决方案并重新构建解决方案。经过所有这些过程,我的应用程序可以正常工作。

So, i can not add a sound file to project.

所以,我不能将声音文件添加到项目中。

This is my code to play sound.

这是我的播放声音的代码。

var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load("bip.wav"); player.Play();

英文:

系统无法找到指定的文件错误,当我向Xamarin Forms项目添加声音文件时。

I add this bip.wav file to Assets folder and i got this the system cannot find the file specified error.

系统无法找到指定的文件错误,当我向Xamarin Forms项目添加声音文件时。

I delete the sound file then clean solution and rebuild solution. After all that processes my app works.
So, i can not add a sound file to project.

This is my code to play sound.

var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load("bip.wav"); player.Play();

答案1

得分: 1

首先,如果您将文件添加到Android部分的Asset文件夹中,您需要将此文件的构建操作(Build Action)设置为AndroidAsset。然后使用AssetManager来读取该文件。AssetManager只能在Android项目中使用。因此,您可以使用Xamarin.Forms DependencyService来调用此Android API。

有关更多详细信息,您可以查看官方文档关于使用Android资产的部分。

另外,您还可以将文件放在共享项目中,并将构建操作设置为嵌入资源(Embedded Resource)。有关更多详细信息,您可以参考这个关于在Xamarin中播放.wav音频的回答。

英文:

First of all, if you added the file in to the Asset folder of the Android part, you need to set the Build Action for this file to AndroidAsset. And then use the AssetManager to read the file. And AssetManager can be only used the android project. So you can use the Xamarin.Forms DependencyService to call this api for the android.

For more details, you can check the official document about Using Android Assets.

In addition, you can also put the file in the share project setting Build Action to Embedded Resource. For more details, you can refer to the accpeted answer in this case about Play .wav audio in Xamarin.

huangapple
  • 本文由 发表于 2023年5月25日 16:42:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76330379.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定