我正在使用 typescript 和 expo-cli 编写一个简单的 react-native 应用程序。我已经导入了 expo-av,但在尝试播放音频时遇到了一些问题。我正在关注 [this guide][1] 但它是用 javascript 编写的,我想这就是问题所在,因为它抱怨类型。
import { Audio } from "expo-av";
export const useAudio = () => {
const [sound, setSound] = useState();
const playSound = async () => {
const { sound } = await Audio.Sound.createAsync( // this line causes the error
require("../assets/sound/ding.mp3")
);
setSound(sound);
await sound.playAsync();
}
};
[![error message][2]][2]
[1]: https://docs.expo.dev/versions/v42.0.0/sdk/audio/
[2]: https://i.stack.imgur.com/PqDgC.png