【发布时间】:2021-12-30 10:28:45
【问题描述】:
我正在尝试构建一个简单的音频播放器,它可以从我们的服务器加载文件并播放它。目前此代码适用于 Android 但 iOS 不工作,抛出错误
AVPlayerItem 实例失败,错误代码 -11850 和域“AVFoundationErrorDomain”
据我所知,这是 iOS 在尝试加载音频文件时需要文件扩展名的问题。我们在我们的 React Web 应用程序上使用完全相同的服务器路由没有问题,它能够在一个简单的音频 html 元素中加载文件。 Android 也可以使用下面的 React Native 代码运行:
const loadNewPlaybackInstance = async playing => {
const source = { uri: url } // defined as `${api}/api/v1/voicemail?s3_email_id=${s3_email_id}`
// This returns a voicemail.wav file
const initialStatus = {
shouldPlay: playing,
rate: 1.0,
volume: volume,
isMuted: false,
}
try {
const { sound } = await Audio.Sound.createAsync(
source,
initialStatus,
onPlaybackStatusUpdate,
)
setPlaybackInstance(sound)
updateScreenForLoading(false)
} catch (error) {
console.error(error.message)
}
}
I've found another SO question, but there isn't a real answer.
There is also an open issue on Github which seems to be forgotten that I've also tried to revive.
有没有人知道如何解决这个问题?让我知道是否需要帮助的更多细节/上下文。
【问题讨论】:
标签: ios react-native expo avaudioplayer expo-av