- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想要一个前端带有波形的音频播放器,并且能够在音频播放器上选择起点和终点并将这些点发送到后端以 trim 音频。另外,如果我可以在音频播放器上拖动这些点来选择特定的部分,那就太好了。
提前致谢
最佳答案
下面是我如何使用 https://wavesurfer-js.org/ 完成的
const EL_play = document.querySelector("#play");
const EL_loop = document.querySelector("#loop");
const RegionsPlugin = WaveSurfer.regions;
const wavesurfer = WaveSurfer.create({
container: "#waveform",
waveColor: "#999",
progressColor: "#000",
mediaControls: true,
loopSelection: true,
plugins: [
RegionsPlugin.create(),
],
});
const Trim = {
loop: EL_loop.checked,
options: {
id: "Trim",
start: 0,
color: "rgba(0, 100, 255, 0.1)",
},
time: 0,
create(re) {
this.options.start = 0; // Set Trim start
this.options.end = wavesurfer.getDuration(); // Set Trim end to match audio duration
wavesurfer.addRegion(this.options); // Add Trim region to WaveSurfer instance
this.Region = wavesurfer.regions.list[this.options.id];
},
trimTime() {
const wasPlaying = wavesurfer.isPlaying();
const re = this.Region;
const isEnd = this.time >= re.end;
this.time = Math.min(Math.max(wavesurfer.getCurrentTime(), re.start), re.end);
if (isEnd) this.time = re.start;
if (isEnd && !this.loop) wavesurfer.pause();
wavesurfer.setCurrentTime(Math.max(0, this.time)); // https://github.com/katspaugh/wavesurfer.js/issues/1816
},
play() {
wavesurfer.playPause();
},
};
const updateUI = () => {
EL_play.classList.toggle("isPlaying", wavesurfer.isPlaying());
};
EL_loop.addEventListener("change", () => Trim.loop = EL_loop.checked); // play pause events
EL_play.addEventListener("click", () => Trim.play()); // play pause events
wavesurfer.on("region-updated", () => Trim.trimTime());
wavesurfer.on("ready", () => Trim.create());
wavesurfer.on("play", updateUI);
wavesurfer.on("pause", updateUI);
wavesurfer.on("audioprocess", () => Trim.trimTime());
wavesurfer.load("http://upload.wikimedia.org/wikipedia/en/4/45/ACDC_-_Back_In_Black-sample.ogg"); // Load Sound!
.wavesurfer-region {
z-index: 0 !important; /* Place Trim "background" below the wave */
pointer-events: none; /* Ignore mouse on trim region */
}
.wavesurfer-handle.wavesurfer-handle-start,
.wavesurfer-handle.wavesurfer-handle-end {
width: 5px !important; /* Easy way to prevent handlers disappear due to width 1% */
pointer-events: auto; /* Allow mouse on trim handlers */
}
.wavesurfer-handle.wavesurfer-handle-start {
background-color: #0bf !important;
}
.wavesurfer-handle.wavesurfer-handle-end {
background-color: #f0b !important;
}
#play:before { content: "\23F5"; }
#play.isPlaying:before { content: "\23F8"; }
<div id="waveform"></div>
<button id="play"></button>
<label><input id="loop" type="checkbox" checked> Loop</label>
<script src="https://unpkg.com/wavesurfer.js"></script>
<script src="https://unpkg.com/wavesurfer.js/dist/plugin/wavesurfer.regions.min.js"></script>
关于javascript - 能够在音频播放器上选择起点和终点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63441902/
我正在使用 Java 编写一个时钟程序,该程序能够“滴答作响”,但它存在问题。我认为它与 getter 和 setter 或 toString() 方法有关。 计数器类 package clock;
const Index = () => { // Ref Links const frefLinks = { 1: useRef(1), 2: useRef(2), 3: useRef(3
所以我读了here不能 pickle 装饰函数。确实: import multiprocessing as mp def deco(f): def wrapper(*args, **kwarg
我在go1.11.2 linux/amd64 版本。当包godog使用 go get github.com/DATA-DOG/godog/ 安装,godog 可执行文件在 $GOPATH/bin/中创
如何正确压缩字符串,以便 PHP 能够解压缩? 我试过这个: public static byte[] compress(String string) throws IOException {
我们这里的问题是表明 在测试中使用 Kleene 代数。 在 b 的值由 p 保留的情况下,我们有交换条件 bp = pb;两个程序之间的等价性简化为等式 在 b 的值不被 p 保留的情况下,我们有交
我有一个与我的网络相关的非常奇怪的问题,我在具有多个接口(interface)的 VirtualBox 上安装了 RDO Grizzly OpenStack。 虚拟盒子: eth0 - managem
我正在尝试使用 Passport.js授权谷歌OAuth2在 Node.js .我整个星期都在尝试让它工作,但不知道为什么它不工作,所以现在我求助于 stack 寻求一些潜在的帮助。我已经尝试了所有在
我是一名优秀的程序员,十分优秀!