Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 能够在音频播放器上选择起点和终点_Javascript_Audio_Ruby On Rails 5 - Fatal编程技术网

Javascript 能够在音频播放器上选择起点和终点

Javascript 能够在音频播放器上选择起点和终点,javascript,audio,ruby-on-rails-5,Javascript,Audio,Ruby On Rails 5,我想有一个前端波形的音频播放器,能够在音频播放器上选择起点和终点,并将这些点发送到后端来修剪音频。另外,如果我可以拖动音频播放器上的这些点来选择特定的部分,那就太好了 提前感谢JavaScript修剪音频文件 下面是我如何使用 const EL_play=document.querySelector(“播放”); const EL#u loop=document.querySelector(“循环”); const RegionsPlugin=WaveSurfer.regions; const

我想有一个前端波形的音频播放器,能够在音频播放器上选择起点和终点,并将这些点发送到后端来修剪音频。另外,如果我可以拖动音频播放器上的这些点来选择特定的部分,那就太好了

提前感谢

JavaScript修剪音频文件 下面是我如何使用

const EL_play=document.querySelector(“播放”);
const EL#u loop=document.querySelector(“循环”);
const RegionsPlugin=WaveSurfer.regions;
const wavesurfer=wavesurfer.create({
容器:“#波形”,
waveColor:#999“,
progressColor:#000“,
媒体控制:对,
选择:对,
插件:[
RegionsPlugin.create(),
],
});
常数微调={
loop:EL_loop.checked,
选项:{
id:“修剪”,
起点:0,
颜色:“rgba(0,100255,0.1)”,
},
时间:0,,
创建(重新){
this.options.start=0;//设置修剪开始
this.options.end=wavesurfer.getDuration();//设置修剪结束以匹配音频持续时间
wavesurfer.addRegion(this.options);//将修剪区域添加到wavesurfer实例
this.Region=wavesurfer.regions.list[this.options.id];
},
trimTime(){
const wasPlaying=wavesurfer.isPlaying();
常数re=该区域;
const isEnd=this.time>=re.end;
this.time=Math.min(Math.max(wavesurfer.getCurrentTime(),re.start),re.end);
如果(isEnd)this.time=重新启动;
if(isEnd&!this.loop)wavesurfer.pause();
wavesurfer.setCurrentTime(数学最大值(0,此时间));//https://github.com/katspaugh/wavesurfer.js/issues/1816
},
play(){
wavesurfer.playPause();
},
};
常量updateUI=()=>{
elu play.classList.toggle(“isplay”,wavesurfer.isplay());
};
EL_loop.addEventListener(“更改”,()=>Trim.loop=EL_loop.checked);//播放暂停事件
EL_play.addEventListener(“单击“,()=>Trim.play());//播放暂停事件
wavesurfer.on(“区域更新”,()=>Trim.trimTime());
wavesurfer.on(“就绪”,()=>Trim.create());
wavesurfer.on(“播放”,更新);
wavesurfer.on(“暂停”,更新);
wavesurfer.on(“audioprocess”,()=>Trim.trimTime());
wavesurfer.load(“http://upload.wikimedia.org/wikipedia/en/4/45/ACDC_-_Back_In_Black-sample.ogg"); // 加载声音!
.wavesurfer区域{
z索引:0!重要;/*将修剪“背景”放置在波浪下方*/
指针事件:无;/*忽略修剪区域上的鼠标*/
}
.wavesurfer-handle.wavesurfer-handle-start,
.wavesurfer-handle.wavesurfer-handle-end{
宽度:5px!重要;/*防止处理程序因宽度1%而消失的简单方法*/
指针事件:自动;/*允许鼠标在修剪处理程序上*/
}
.wavesurfer-handle.wavesurfer-handle-start{
背景色:#0bf!重要;
}
.wavesurfer-handle.wavesurfer-handle-end{
背景色:#f0b!重要;
}
#播放:在{内容:“\23F5”}之前
#play.isPlaying:在{内容:“\23F8”;}之前

HTML5视频API到目前为止您尝试的代码在哪里?请创建一个。如果有疑问,请阅读。@GetSet我将检查HTML5视频API。Thanks@RokoC.Buljan到目前为止,我已经使用HTML5音频播放器,并使用它的搜索处理程序来选择开始和结束时间,但它不是用户交互的。我检查了wavesurfer.js,它有带波形的音频播放器,但找不到任何示例或事件处理程序来选择音频开始和结束时间。