2

当我尝试从本地后端播放音频或从站点上载的音频时,我不断收到此错误。无论是什么文件格式,这都是我得到的,而且这只发生在 ios

错误:Possible Unhandled Promise Rejection (id: 0): Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain". Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain". 错误图像

const player = new Audio.Sound();
player.loadAsync({ uri: url }, initialStatus).then(() => {
    player.playAsync().then((playbackStatus) => {
        if (playbackStatus.error) {
                                 
          handlePlaybackError(playbackStatus.error);
        }
    });
});

添加更多错误处理后,我发现错误来自 loadAsync,并且仅在我尝试从本地后端服务器播放音频时才会发生。(ex: http://127.0.0.1:8000/media/audios/2021/08/08/27/21/filename.mp4)

如果我能在这方面得到帮助,那就太好了,在此先感谢!更新:提供更多代码

4

2 回答 2

2

因此,我发现正在生成该警告并阻止我的音频文件播放,因为它们存储在我的本地服务器中,并且由于某种原因,expo Audio.Sound 对象在加载它们时出现问题,所以我必须安装expo-file-system,使用FileSystem读取下载文件并使用下载生成的 uri。例子:

import * as FileSystem from 'expo-file-system';

    const splitUrl = url.split('/');
    const lastItem = splitUrl[splitUrl.length - 1];
    const { uri } = await FileSystem.downloadAsync(
        url,
        FileSystem.documentDirectory + lastItem
    );
    const source = { uri: uri }; //the source you provide to the loadAsync() method

于 2021-09-01T02:05:09.240 回答
1

loadAsync() 返回一个 Promise,所以你必须等待它。如果这不是您必须提供更多代码的问题,请。

这是文档,所以像这样使用它:

const sound = new Audio.Sound();
try {
  await sound.loadAsync(require('./assets/sounds/hello.mp3'));
  await sound.playAsync();
  // Your sound is playing!

  // Don't forget to unload the sound from memory
  // when you are done using the Sound object
  await sound.unloadAsync();
} catch (error) {
  // An error occurred!
}

这是我做的一个简单的小吃,它对我有用,你可能想考虑使用 try-catch 进行错误处理: 小吃示例

于 2021-08-31T07:49:54.220 回答