Published
Edited
Jul 17, 2020
1 fork
Insert cell
md`# Draggable Audio Heads`
Insert cell
vidya = html`<div font-family="Roboto" style="font-weight:bold">Drag Me!!!!!</div><br>Get closer to either Brent or Oscar to listen in on their conversation.<br><br>${await FileAttachment("butt.png").image()}
<video id="video" draggable="true" ondragstart="event.dataTransfer.setData('text/plain',null)" width="600" height="600" class="cool-border" autoplay></video>
<span style="float: right">${await FileAttachment("oscar.png").image()}</span>`
Insert cell
{
vidya;
var video = document.getElementById('video');

if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ video: true, audio: false }).then(function(stream) {
video.srcObject = stream;
video.play();
});
}
}
Insert cell
audya = html`
<audio id="brent_noise">
<source src=${await FileAttachment("brent.mp3").url()} type="audio/mpeg">
</audio>

<audio id="oscar_noise">
<source src=${await FileAttachment("oscar.mp3").url()} type="audio/mpeg">
</audio>
`
Insert cell
{
audya;
document.getElementById("oscar_noise").play();
document.getElementById("brent_noise").play();

document.getElementById("oscar_noise").volume = 100 / 900;
document.getElementById("brent_noise").volume = (900 - 100) / 900;
}
Insert cell
{
vidya; audya;
var video = document.getElementById('video');
//https://stackoverflow.com/questions/38655964/how-to-remove-dragghost-image#
document.addEventListener("dragstart", function( event ) {
var img = new Image();
img.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=';
event.dataTransfer.setDragImage(img, 0, 0);
}, false);
var drag_handler = function(e) {
e.preventDefault();
if (e.clientX != 0) {
e.target.style.left = e.clientX + "px";
document.getElementById("oscar_noise").volume = e.clientX / 900;
document.getElementById("brent_noise").volume = (900 - e.clientX) / 900;
}
}
video.addEventListener("drag", drag_handler);
}
Insert cell
my_css = html`<style>
#video {
width: 100px;
height: 100px;
border-radius:50%;
object-fit: cover;
position: absolute;
left: 100px;
}

img {
width: 100px;
height: 100px;
border-radius:50%;
object-fit: cover;
}

.cool-border, img {
border-color:CornflowerBlue;
border-style:solid;
border-width:3px;
}
</style>
`
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more