【问题标题】:Add sound effect on splash screen with react native使用本机反应在启动画面上添加音效
【发布时间】:2021-08-25 02:36:21
【问题描述】:

我正在尝试使用 react-native 向我的 ** 初始屏幕 ** 添加声音效果,我已经使用 ** react-native-bootsplash ** 完成了,但我不知道如何添加音效。 提前致谢,问候...

【问题讨论】:

    标签: react-native react-native-android splash-screen react-native-cli


    【解决方案1】:

    您可以使用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)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-09
      • 2023-01-24
      • 2020-05-29
      • 1970-01-01
      相关资源
      最近更新 更多