【发布时间】:2021-08-25 02:36:21
【问题描述】:
我正在尝试使用 react-native 向我的 ** 初始屏幕 ** 添加声音效果,我已经使用 ** react-native-bootsplash ** 完成了,但我不知道如何添加音效。 提前致谢,问候...
【问题讨论】:
标签: react-native react-native-android splash-screen react-native-cli
我正在尝试使用 react-native 向我的 ** 初始屏幕 ** 添加声音效果,我已经使用 ** react-native-bootsplash ** 完成了,但我不知道如何添加音效。 提前致谢,问候...
【问题讨论】:
标签: react-native react-native-android splash-screen react-native-cli
您可以使用react-native-sound-player 为您的启动画面添加声音。
On iOS, drag and drop sound file into project in Xcode. Remember to check "Copy items if needed" option and "Add to targets".
On Android, put sound files in {project_root}/android/app/src/main/res/raw/. Just create the folder if it doesn't exist.
import SoundPlayer from 'react-native-sound-player'
try {
// play the file tone.mp3
SoundPlayer.playSoundFile('tone', 'mp3')
// or play from url
SoundPlayer.playUrl('https://example.com/music.mp3')
} catch (e) {
console.log(`cannot play the sound file`, e)
}
【讨论】: