【发布时间】:2022-12-17 01:45:37
【问题描述】:
嗨,我正在尝试使用 Expo-AV,但一直收到警告
[Unhandled promise rejection: Error: Cannot load an AV asset from a null playback source]
当第一次调用声音播放功能时,它会显示此警告并且不会播放,但是当我再次调用它播放的功能时,它会在没有警告的情况下播放。
const [sound, setSound] = useState();
const [isPlaying, setIsPlaying] = useState(false);
async function playSound() {
console.log("Loading Sound");
const { sound } = await Audio.Sound.createAsync(
{ uri },
{ shouldPlay: true }
);
setSound(sound);
console.log("Playing Sound");
setIsPlaying(true);
await sound.playAsync();
sound._onPlaybackStatusUpdate = (status) => {
if (status.didJustFinish) {
setIsPlaying(false);
console.log("Finished");
}
};
}
<TouchableOpacity onPress={playSound()}>
<Text>Play</Text>
</TouchableOpacity>
无论如何加载正确后是否可以播放。
【问题讨论】:
-
检查
uri是不是undefined? -
没有 url 不是未定义的:(
-
我也遇到了同样的问题。有趣的是,视频也开始崩溃。
标签: react-native expo expo-av