0

我有堆叠卡片的应用程序(很多卡片 - 大约 500 张)

我添加的卡片组件:

function getVoice() {
    try {
        const mySound = new Sound(getSoundName(id), Sound.MAIN_BUNDLE,
            (error) => {
                if (error) {
                    Alert.alert('Error:', error.message)
                    return;
                }
            })

        if (mySound != null) {
            mySound.play((success, error) => {
                if (success) {
                    Alert.alert('success')
                } else {
                    Alert.alert('err')
                }
                mySound.release()
            })
        }
    }
    catch{

    }
};

此处触发警报err

怎么了?

我尝试了另一种选择。

new Sound()在组件加载开始时调用

声音在这里播放,但最多可用于 8 张卡片。后来有和现在一样的错误

4

1 回答 1

0

它工作正常:

const getVoice = () => {
    try {
        const sound = new Sound(getSoundName(id), null, (error) => {
            if (error) {
                return;
            }

            sound.play();
        });
    }
    catch{
    }
};
于 2020-03-13T16:09:51.287 回答