账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    react里怎么用原生video和audio
    • 2019-05-07 00:00
    • 10
    22
    -1

    就算放在跟节点外面也不行,播放器出来了但就是不能播放

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • -1
    • 人贱不如不见 普通会员 1楼

      在React中,你可以使用react-native-videoreact-native-audio库来处理原生的video和audio。

      以下是一个基本的示例:

      ```jsx import React from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import { StyleSheet, Image, View, TouchableOpacity, Text } from 'react-native'; import { Video, Audio } from 'react-native-video';

      const App = () => { return ( {Video.getVideoByURL('https://www.youtube.com/watch?v=dQw4w9WgXcQ');}} style={styles.button}> Play Video {Audio.setAudio('https://www.example.com/audio.mp3');}} style={styles.button}> Play Audio ); };

      const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#f5f5f5', }, button: { backgroundColor: '#4CAF50', borderRadius: 4, padding: 10, alignItems: 'center', justifyContent: 'center', }, buttonText: { fontSize: 18, color: '#ffffff', }, });

      export default App; ```

      在这个示例中,我们首先导入了VideoAudio组件,然后在App组件中,我们为每个按钮添加了一个TouchableOpacity组件,当用户点击按钮时,它们会调用相应的函数。这两个函数分别是Video.getVideoByURLAudio.setAudio,分别用于获取指定URL的视频和音频。最后,我们为每个按钮添加了一个文本组件,用于显示按钮的文本。

      请注意,你需要先安装react-native-videoreact-native-audio库才能在你的项目中使用它们。你可以使用npm来安装它们:

      bash npm install react-native-video react-native-audio

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部