reactjs - 如何在本机反应中呈现html音频标签?
问题描述
为什么 react-native-html-render 不渲染 html 音频标签?这个库可以做到吗?由于有 iframe 插件来处理视频,感觉应该有一个插件来处理音频,但我找不到。提前致谢。
解决方案
您还可以使用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>
);
}
推荐阅读
- php - PHP警告:require_once:无法打开流:没有这样的文件或目录
- git - git commit 显示编码标准未安装 git commit
- php - PHP - 如果复选框的值在数组中,则检查它们
- r - 将所有单词转换为大写
- jakarta-ee - Wildfly 部署后不会在 jar 中加载 dll
- r - R - 以字符、时间和日期变量为条件的嵌套 ifelse 错误
- excel - 在不安装驱动程序的情况下从 excel 访问 sqlite 数据库
- selenium - Yii2 Codeception 接受类名必须是有效对象或字符串
- visual-studio-code - 附加编辑器亮点是否有可互换的定义?
- python-3.x - OpenCV 无法将模板与图像匹配(matchTemplate)