javascript - 如何在本机反应中预加载音频文件?
问题描述
我现在正在开发一个媒体播放器,但我很想找到一个解决方案,我可以预加载前 4 个音频文件,当我去下一个时,预加载的功能将再次运行。我正在使用一个带有 url 路径的数组,每个数组都指向非本地的 s3 存储桶。我还想提一下我正在使用expo-av
包
现在加载看起来像这样
componentDidMount() {
Audio.setAudioModeAsync({
allowsRecordingIOS: false,
staysActiveInBackground: false,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
playsInSilentModeIOS: true,
shouldDuckAndroid: true,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
playThroughEarpieceAndroid: false
});
}
async _loadNewPlaybackInstance(playing) {
if (this.playbackInstance != null) {
await this.playbackInstance.unloadAsync();
this.playbackInstance = null;
}
const source = { uri: PLAYLIST[this.index].url };
const initialStatus = {
shouldPlay: playing,
rate: this.state.rate,
shouldCorrectPitch: this.state.shouldCorrectPitch,
volume: this.state.volume,
};
const { sound, status } = await Audio.Sound.createAsync(
source,
initialStatus,
this._onPlaybackStatusUpdate
);
this.playbackInstance = sound;
if (status) {
this._onPlayPausePressed()
}
this._updateScreenForLoading(false);
}
解决方案
推荐阅读
- centos7 - 如何从 CLI 检查 MOBO 是否支持 WOL?
- react-native - 将本机帖子反应到快递服务器时可能出现未处理的承诺拒绝
- batch-file - 如何使用批处理读取从串口接收到的数据?
- c++ - 从文件 C++ 中删除一行
- django - 找不到 Django 项目页面
- jquery - 使用多选下拉菜单进行多选过滤 - jQuery
- sql - 在 VBA 中运行时 SQL 查询未显示所有结果
- javascript - 用户关闭网页时如何删除链接颜色的本地存储
- sql - 尝试使用 LAG 计算行之间的百分比变化
- laravel - 如何使用foreach循环在laravel控制器返回值中按姓氏排序