我使用React-Howler在我的React应用中播放声音。在我的组件的顶部,我有以下导入:
import ReactHowler from 'react-howler';
import React, {Component} from 'react';
class SamplesInnerLrg extends Component {
playSampleAction(sampleSource) {
var sound = new Howl({
src: [sampleSource]
})
}
render() {
<div>
<div onClick={this.playSampleAction("url to some source")}>Play</div>
<ReactHowler src={"url to some source"} playing={true} />
</div>
}
当我渲染组件时,它会播放来自组件的声音但是当我点击div时说“&#34;播放&#34;它告诉我Howl没有定义。我试过用两种方式定义嚎叫:
var Howl = require('howler').Howl;
或
import { Howl } from 'react-howler'
但是没有工作。不确定导入嚎叫我做错了什么!
答案 0 :(得分:0)
确保您在浏览器中包含Howler脚本:
<script src="/path/to/howler.js"></script>
<script>
var sound = new Howl({
src: ['sound.webm', 'sound.mp3']
});
</script>