Rob*_*aty 6 javascript react-native expo
我正在使用 React Native 和 Expo 制作应用程序。
我的目标
您可以从手机导入一些音频,当您按下按钮时,此按钮会播放音频。
我正在使用 Expo,所以我安装了 ExpoDocumentPicker。我首先尝试了这个:
DocumentPicker.getDocumentAsync();
Run Code Online (Sandbox Code Playgroud)
这段代码非常适合从手机中挑选任何文件。但我更喜欢只选择音频选项,以提高灵活性并防止将来出现错误。
所以我查看了 ExpoDocumentPicker 文档,我找到了我的问题的所谓“解决方案”(我首先尝试在 Youtube 和 Google 上搜索,但对我没有任何作用)。
我尝试了在文档中找到的这段代码:
await DocumentPicker.getDocumentAsync
({
type: ["audio/*"],
});
Run Code Online (Sandbox Code Playgroud)
预期行为
当用户按下按钮时,应用程序会打开手机文件浏览器,仅用于音频
发生了什么
这在网络上非常有效。但是后来我在我的 Android 手机上试了一下,但没有用。
我收到以下错误消息:
[Unhandled promise rejection: Error: Encountered an exception while calling native method: Exception occurred while executing exported method getDocumentAsync on module ExpoDocumentPicker: java.util.ArrayList cannot
be cast to java.lang.String]
Run Code Online (Sandbox Code Playgroud)
以及完整的错误日志:
[Unhandled promise rejection: Error: Encountered an exception while calling native method: Exception occurred while executing exported method getDocumentAsync on module ExpoDocumentPicker: java.util.ArrayList cannot
be cast to java.lang.String]
- node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:103:50 in promiseMethodWrapper
- node_modules\@unimodules\react-native-adapter\build\NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
- node_modules\expo-document-picker\build\index.js:2:7 in getDocumentAsync
- node_modules\regenerator-runtime\runtime.js:45:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:274:29 in invoke
- node_modules\regenerator-runtime\runtime.js:45:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:135:27 in invoke
- node_modules\regenerator-runtime\runtime.js:170:16 in PromiseImpl$argument_0
- node_modules\promise\setimmediate\core.js:45:6 in tryCallTwo
- node_modules\promise\setimmediate\core.js:200:22 in doResolve
- node_modules\promise\setimmediate\core.js:66:11 in Promise
- node_modules\regenerator-runtime\runtime.js:169:15 in callInvokeWithMethodAndArg
- node_modules\regenerator-runtime\runtime.js:192:38 in enqueue
- node_modules\regenerator-runtime\runtime.js:219:8 in exports.async
* http://192.168.0.7:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:136666:37 in getDocumentAsync
* src\pages\start-page\index.js:42:2 in teste
- node_modules\regenerator-runtime\runtime.js:45:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:274:29 in invoke
- node_modules\regenerator-runtime\runtime.js:45:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:135:27 in invoke
- node_modules\regenerator-runtime\runtime.js:145:18 in PromiseImpl.resolve.then$argument_0
- node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:135:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:183:16 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:446:30 in callImmediates
* [native code]:null in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:396:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:144:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:373:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:143:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue
Run Code Online (Sandbox Code Playgroud)
我认为错误与什么有关
我认为这个错误是因为我没有向用户请求许可,所以我下载了 ExpoPermissions 并在函数中添加了这些行:
await Permissions.askAsync(
Permissions.CAMERA_ROLL
)
Run Code Online (Sandbox Code Playgroud)
但是这些行并没有改变任何东西......
我当前的代码
这是我目前仍然无法正常工作的代码:
async function onBtnPress(){
await Permissions.askAsync(
Permissions.CAMERA_ROLL
)
await DocumentPicker.getDocumentAsync
({
type: ["audio/*"],
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
151 次 |
| 最近记录: |