我正在尝试使用 jquery UI 拖放来混合多个音频。意味着我将在音频上下文中动态添加轨道,并将其放在容器上。使用 XMLHttpRequest 删除后,我可以获取跟踪缓冲区。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Sortable - Connect lists</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
table {
font-size: 1em;
}
.ui-draggable, .ui-droppable {
background-position: top;
}
#sortable1, #sortable2 {
border: 1px solid #eee;
width: 142px;
min-height: 20px;
list-style-type: none;
margin: 0;
padding: 5px 0 0 0;
float: left;
margin-right: 10px;
}
#sortable1 li, #sortable2 li {
margin: 0 5px 5px 5px;
padding: 5px;
font-size: 1.2em;
width: 120px;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
var buffers = [];
window.AudioContext = (window.AudioContext ||
window.webkitAudioContext ||
window.mozAudioContext ||
window.oAudioContext ||
window.msAudioContext);
if (!AudioContext) alert('This site cannot be run in your Browser. Try a recent Chrome or Firefox. ');
var audioContext = new AudioContext();
$( function() {
$( "#sortable1" ).droppable({
helper: "clone",
revert: "invalid",
accept: ".ui-state-highlight",
drop: function(e, ui){
console.log(ui.draggable.data('url'));
}
}).disableSelection();
$( "#sortable2").sortable({
revert: true,
connectWith: ".connectedSortable"
}).disableSelection();
function loadMusic(url) {
var req = new XMLHttpRequest();
req.open( "GET", url, true );
req.responseType = "arraybuffer";
req.onreadystatechange = function (e) {
if (req.readyState == 4) {
if(req.status == 200)
audioContext.decodeAudioData(req.response,
function(buffer) {
var id = '_' + Math.random().toString(10).substr(2, 9)
buffers[id] = {
buffer: buffer,
start: 1,
to: 5
};
}, onDecodeError);
else
alert('error during the load.Wrong url or cross origin issue');
}
};
req.send();
}
// I have buffers array, how I can merge the dropped tracks by dynamic positions using start and end
} );
</script>
</head>
<body>
<ul id="sortable1" class="connectedSortable">
</ul>
<ul id="sortable2" class="connectedSortable">
<li class="ui-state-highlight" data-url="https://twgljs.org/examples/sounds/DOCTOR%20VOX%20-%20Level%20Up.mp3">Song 1</li>
<li class="ui-state-highlight" data-url="https://freesound.org/data/previews/449/449593_7037-lq.mp3">Song 1</li>
<li class="ui-state-highlight" data-url="https://freesound.org/data/previews/449/449554_2454046-lq.mp3">Song 1</li>
</ul>
</body>
</html>
我现在可以做些什么来合并丢弃的曲目并实时播放?我对 javascript 音频上下文非常陌生。