Mobile Audio issue

22 views
Skip to first unread message

Stiev Stigma

unread,
Sep 6, 2017, 1:00:31 PM9/6/17
to CoSpaces Scripting
So I'm pretty convinced this is a bug at this point, having checked, rechecked, and rewritten, this script in addition to reformatting and reloading the audio files. For some reason I have no problems with audio playback in the browser but when I test it on mobile (iPhone 7plus and Android), the audio doesn't seem to load. 

Here's the code. If anyone can provide some insight as to the issue I'm at my wit's end with this one,lol:

var kick; 
var snare;
var kickisPlaying = false;
var snareisPlaying = false;
var cHatisPlaying = false;
var oHatisPlaying = false;

var booleanToggle;
booleanToggle = false;
var debug;
debug = Scene.getItem("TswbK8TCr1");

var playButton;
var plyBut2;
var toggleBut;
var hatButt1;
playButton = Scene.getItem("587H69jNH5");
plyBut2 = Scene.getItem("NGuGwBdkoI");
hatButt1 = Scene.getItem("HH3RfUcgsx");

toggleBut = Scene.getItem("ZtMFaCSu0q");
let currentTime = Scene.currentTime();
let soundClipId = 'Xtt6BJaiAuuAsOBXoG2CwhPYAhrgbtOj6ZfMbr6QSYH'
let soundClipId2 ='XTOUJIJRI63RdotSaRiU5ieLpHxvo94upRV4ytxfxKK'
let soundClipId3 = 'fkYF1AIgH0LeRnEGQnK6xST5DuGInYghCtO8Cr7UUNv'
let startTime = currentTime + 0.100;
let BPM = 190;
let quarterTime = (60/BPM);
let eighthTime = (quarterTime/2);
let sixteenthTime = (eighthTime/2);
 

 //Kick Loop
function fourOnTheFloor(){
    kickisPlaying = true;
    Scene.loadSound(soundClipId, function(kick) {
    debug.say('start'+ startTime)
let kickLoop = Scene.scheduleRepeating(function() {
    // Play the kick drum on beats 1, 2, 3, 4
    Scene.schedule(kick.play, startTime);
    Scene.schedule(kick.play, startTime + quarterTime);
    Scene.schedule(kick.play, startTime+ 2*quarterTime);
    Scene.schedule(kick.play, startTime+ 3*quarterTime);
        if(!kickisPlaying){kickLoop.dispose();}
}, 4*quarterTime);
    })};
        
//Snare Loop
function straightSnare(){
    snareisPlaying = true;
    Scene.loadSound(soundClipId2, function(snare) {
    debug.say('start'+ startTime);
let snareLoop = Scene.scheduleRepeating(function() {
    // Play the snare drum on beats  2,  4
    Scene.schedule(snare.play, startTime + quarterTime);
    Scene.schedule(snare.play, startTime+ 3*quarterTime);
        if(!snareisPlaying){snareLoop.dispose();}
}, 4*quarterTime);
    })};

//ccHat Loop
function cHat(){
    cHatisPlaying = true;
    Scene.loadSound(soundClipId3, function(cHat) {
    debug.say('start'+ startTime)
let cHatLoop = Scene.scheduleRepeating(function() {
    // Play the snare drum on beats  2,  4
    Scene.schedule(cHat.play, startTime + eighthTime);
    Scene.schedule(cHat.play, startTime+ 2*eighthTime);
    Scene.schedule(cHat.play, startTime+ 3*eighthTime);
    Scene.schedule(cHat.play, startTime+ 4*eighthTime);
    Scene.schedule(cHat.play, startTime+ 5*eighthTime);
    Scene.schedule(cHat.play, startTime+ 6*eighthTime);
    Scene.schedule(cHat.play, startTime+ 7*eighthTime);
        if(!cHatisPlaying){cHatLoop.dispose();}
}, 8*eighthTime);
    })};

//Loop Button
toggleBut.onActivate(function()
{
    debug.say('Pressed')
    if(!booleanToggle){toggleBut.setColor(5,255,5);
    booleanToggle = true;
    fourOnTheFloor()
    straightSnare()
    cHat()
    }
    else if(booleanToggle){toggleBut.setColor(255,5,5);
    booleanToggle = false;
    var kickisPlaying = false;
var snareisPlaying = false;
var cHatisPlaying = false;
var oHatisPlaying = false;
    }
});

//Kick Start
playButton.onActivate(function()
{
    debug.say('Pressed')
    if (!kickisPlaying){
        fourOnTheFloor() 
    }
    else if(kickisPlaying){kickisPlaying = false;}
});

//Snare Start
plyBut2.onActivate(function()
{
    debug.say('Pressed')
    if (!snareisPlaying){
        straightSnare()
    }
    else if(snareisPlaying){snareisPlaying = false;}
    
});

//cHat Start
hatButt1.onActivate(function()
{
    debug.say('Pressed')
    if (!cHatisPlaying){
        cHat()
    }
    else if(cHatisPlaying){cHatisPlaying = false;}
    
});

Pavel Kakolin

unread,
Sep 6, 2017, 1:26:54 PM9/6/17
to cospaces-...@googlegroups.com
Hi! Try to replace all the calls like

Scene.schedule(sound.play, startTime);

with calls like

Scene.schedule(function() {sound.play();}, startTime);

Then it should start working on mobile devices as well.

Your code is correct and most likely does not work on mobile devices because of a bug in CoSpaces javascript engine. We will dig into this, but for now you can use workaround that I suggested above.

Stiev Stigma

unread,
Sep 6, 2017, 4:05:48 PM9/6/17
to CoSpaces Scripting
It worked like a charm. Thanks! 
Now I'm wondering why it worked. If my enclosures were wrong shouldn't it throw an error in the browser as well?

Pavel Kakolin

unread,
Sep 6, 2017, 6:01:13 PM9/6/17
to cospaces-...@googlegroups.com
Your code was not wrong, that's why it worked in the browser. 

It's only CoSpaces for mobile devices that has currently a bug that allows to schedule user-defined functions (for example function() {sound.play();}), but does not allow to schedule CoSpaces function (for example sound.play).

This bug will be fixed in coming updates, supposedly next week.
Reply all
Reply to author
Forward
0 new messages