【问题标题】:How to render html audio tag in react native?如何在本机反应中呈现html音频标签?
【发布时间】:2021-12-22 02:55:50
【问题描述】:

为什么 react-native-html-render 不渲染 html 音频标签?这个库可以做到吗?由于有 iframe 插件来处理视频,感觉应该有一个插件来处理音频,但我找不到。提前致谢。

【问题讨论】:

标签: reactjs react-native plugins react-native-render-html render-html


【解决方案1】:

您还可以使用 expo-av 库在您的应用中播放音频 (https://docs.expo.dev/versions/latest/sdk/audio/)

import * as React from 'react';
import { Text, View, StyleSheet, Button } from 'react-native';
import { Audio } from 'expo-av';

export default function App() {
  const [sound, setSound] = React.useState();

  async function playSound() {
    console.log('Loading Sound');
    const { sound } = await Audio.Sound.createAsync(
       require('./assets/Hello.mp3')
    );
    setSound(sound);

    console.log('Playing Sound');
    await sound.playAsync(); }

  React.useEffect(() => {
    return sound
      ? () => {
          console.log('Unloading Sound');
          sound.unloadAsync(); }
      : undefined;
  }, [sound]);

  return (
    <View style={styles.container}>
      <Button title="Play Sound" onPress={playSound} />
    </View>
  );
}

【讨论】:

    猜你喜欢
    • 2019-05-13
    • 2013-01-24
    • 1970-01-01
    • 2022-09-16
    • 2021-12-13
    • 2019-01-09
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多