Я делаю приложение, используя React Native и Expo.
Моя цель
Вы можете импортировать звук со своего мобильного телефона, и когда вы нажимаете кнопку, эту кнопку воспроизводит звук.
Я использую Expo, поэтому я установил ExpoDocumentPicker. Я сначала попробовал это:
DocumentPicker.getDocumentAsync();
И этот код очень хорошо работал, чтобы выбрать любой документ с мобильного телефона. Но я предпочитаю выбирать только аудио вариант для гибкости и предотвращения ошибок в будущем.
Итак, я заглянул в документы ExpoDocumentPicker и нашел предполагаемое «решение» моих проблем (сначала я попытался выполнить поиск по Youtube и Google, но у меня ничего не получилось).
И я попробовал этот код, который нашел в документации:
await DocumentPicker.getDocumentAsync
({
type: ["audio/*"],
});
Ожидаемое поведение
Когда пользователь нажимает кнопку, приложение открывает проводник файлов мобильного телефона только для aud ios
Что произошло
Это очень хорошо работало в Интернете. Но затем я попробовал свой 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]
И полный журнал ошибок :
[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
Я думал, что ошибка связана
Я думал, что эта ошибка возникла из-за того, что я не спрашивал разрешения у пользователя, поэтому я загрузил ExpoPermissions и Я добавляю эти строки в функцию:
await Permissions.askAsync(
Permissions.CAMERA_ROLL
)
Но эти строки ничего не изменили ...
Мой текущий код
И это мой текущий код, который все еще не работает:
async function onBtnPress(){
await Permissions.askAsync(
Permissions.CAMERA_ROLL
)
await DocumentPicker.getDocumentAsync
({
type: ["audio/*"],
});
}