【发布时间】:2019-03-07 10:22:52
【问题描述】:
我想播放我使用 CrossSimpleAudioPlayer 插件下载的声音。
我实例化并初始化插件,在 IOS 上一切正常,但在 android 上,当我加载文件“Java.IO.FileNotFoundException”时,它给了我这个错误 但文件存在且有读取权限
并且在控制台上出现这个“[MediaPlayer] error (1, -2147483648)”。
我以这种方式加载剪辑
ISimpleAudioPlayer player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
player.Load("/data/user/0/com.my.app/files/20.wav");
当我使用 Stream 加载时,向我抛出错误“Java.IO.IOException: Prepare failed.: status=0x1”
var temp = new MemoryStream(DependencyService.Get<IFileHelper>().GetFileAsByte(path));
//This works fine and loads the file
player.Load(temp); //throws the error
如果我加载链接而不是本地文件,这可以正常工作,但我需要一个本地文件。
我不知道为什么在 Android 上会发生这种情况
【问题讨论】:
-
您的文件在哪里?在模拟器、真实设备或 VS 项目中。
-
如果音频文件是从Android本地资源文件夹加载的,请确保音频文件通过属性选择设置到Bundle Resource中
-
@CGPA6.4 文件在真机中,路径正确
-
可能 CrossSimpleAudioPlayer 没有那么强大,在 Android 中无法获得这样的路径。尝试使用原生 android 方法
MediaPlayer来做。 DependencyService 可能有用。docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/… -
@JuniorJiang-MSFT 这也不起作用。出现同样的错误
标签: xamarin xamarin.forms