Stopping audio when not hovering

33 views
Skip to first unread message

JM

unread,
Sep 13, 2017, 7:26:21 PM9/13/17
to CoSpaces
Hi All - 

Can you use Blockly to play audio when hovering on an object and stop the audio when not hovering? 

I can get audio to start playing on hover (using On Hover of "X" On: Play Sound "A.MP3"), but I would like to have the audio stop when the user stops hovering on an object.  

I have tried deselecting "Wait until finished" and playing an audio file with no sound in the same script as part of the Off - i.e, Off: Play Sound "Silence.MP3". 

Thanks! 

Benjamin Singh

unread,
Sep 14, 2017, 3:53:19 AM9/14/17
to cospace...@googlegroups.com
Hi,

at the moment it doesn't seem possible to do so only using Blockly. I'll talk to the team, maybe we can find a solution for this by adding a new block for example. Nevertheless, here is a JavaScript snippet you can use as a temporarily solution:

var button = Scene.getItem('button');

var soundClipId = '58srYb0TXZiS0mGDUsTTcpwSki3Ew5QtcsHJNrgrY4b';
var soundClip = Scene.loadSound(soundClipId);

button
.onHover(function(isHovered) {
   
if(isHovered) {
        soundClip
.play();
   
} else {
        soundClip
.stop();
   
}
});

Link to the example: https://cospac.es/U84D

You can find the details to these functions in the API documentation.

Benjamin

Reply all
Reply to author
Forward
0 new messages