我正在使用 wavesurfer 包播放音频文件。我正在使用状态变量来播放,暂停循环中的音频文件,但是当我按下播放按钮时播放特定文件时遇到问题,它会播放所有文件,因为我正在使用状态变量作为“播放”变量播放。请参见上文代码。
import React, { Component } from 'react';
import Wavesurfer from 'react-wavesurfer';
window.WaveSurfer = require("wavesurfer.js");
let Regions = require("react-wavesurfer/lib/plugins/regions").default;
let Minimap = require("react-wavesurfer/lib/plugins/minimap").default;
class DashboardPage extends Component{
constructor(props){
super(props);
this.state = {
recordings:objectOfRecordings,
playing: false,
pos: 0
};
this.handleChange = this.handleChange.bind(this);
this.handleTogglePlay = this.handleTogglePlay.bind(this);
this.handlePosChange = this.handlePosChange.bind(this);
};
handleTogglePlay() {
this.setState({
playing: !this.state.playing
});
}
handlePosChange(e) {
this.setState({
pos: e.originalArgs[0]
});
}
render(){
const { recordings } = this.state;
return(
<div>
<h1>Dashboard</h1>
<div className="recording">
<ul className="list-group">
{
recordings &&
recordings.map((prop,key)=>{
return (
<li className="list-group-item" key={key}>
<Wavesurfer
audioFile={prop.comment_url}
pos={this.state.pos}
onPosChange={this.handlePosChange}
playing={this.state.playing}
/>
<button onClick={this.handleTogglePlay}>play</button>
</li>
)
})
}
</ul>
</div>
</div>
);
}
}
export default Dashboard;
请建议我更好的解决方案来播放特定文件。