加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – 在事件中对原生播放声音做出反应

发布时间:2020-12-15 20:50:34 所属栏目:百科 来源:网络整理
导读:我有一个组件,如: import React,{ Component } from 'react'import { StyleSheet,Text,View,TouchableOpacity } from 'react-native'class MovieList extends Component { handlePress() { // Play some sound here } render() { const { movie } = this.pr
我有一个组件,如:
import React,{ Component } from 'react'
import { StyleSheet,Text,View,TouchableOpacity } from 'react-native'


class MovieList extends Component {


    handlePress() {
        // Play some sound here
    }

    render() {
        const { movie } = this.props
        return (
            <TouchableOpacity onPress={this.handlePress.bind(this)}>
                <View style={styles.movie}>
                    <Text style={styles.name}>{movie.name}</Text>
                    <View style={styles.start}>
                        <Text style={styles.text}>Start</Text>
                    </View>
                </View>
            </TouchableOpacity>
        )
    }
}

在这里,当我触摸视图时,我想播放一些声音.
我搜索了它,但没有找到任何适当的答案

无论如何,当我按下某些东西时,我能发出声音吗?
我怎样才能做到这一点 ?

查看 React Native Sound – 用于访问设备音频控件的跨平台组件.

您可以像这样使用它:

const Sound = require('react-native-sound')

let hello = new Sound('hello.mp3',Sound.MAIN_BUNDLE,(error) => {
  if (error) {
    console.log(error)
  }
})

hello.play((success) => {
  if (!success) {
    console.log('Sound did not play')
  }
})

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读