为什么 react-native-html-render 不渲染 html 音频标签?这个库可以做到吗?由于有 iframe 插件来处理视频,感觉应该有一个插件来处理音频,但我找不到。提前致谢。
问问题
80 次
1 回答
0
您还可以使用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>
);
}
于 2021-11-09T19:50:36.203 回答