Hi Liam! I did this by using the JS-only part of the code component and the “Begin Experiment, Begin Routine, End Routine” tabs. The conversion from .py to .js is sometimes wonky but I think this is very straightforward to write directly in .js (at least it worked for me and I know nothing about javascript).
What I did was the following…
Begin Experiment tab: define a .js function shuffle (literally could cop/paste what i have here), start an iterator at 0, make a list of your audio files:
function shuffle(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}
t_2 = 0; // start iterator at 0
music_list = ['007','010','014','028',
'031','034','038',
'067','069','078',
'095','096','100',
'105','109','110']; // names of my audio files
Begin Routine tab: define current_target as targets[current_iterator]. As you have done I put $music_play in the sound component.
var stim = "Stimuli/"; //subfolder to find the audio file in
var mp3 = ".mp3"; //file type to appended to the end
var music_play = stim.concat(music_list[t_2],mp3); //concatenate folder, audio file name (by indexing the list), and .mp3
psychoJS.experiment.addData('musicPlayed', music_play) // add to log
End Routine tab: +1 to your iterating variable
t_2 = t_2+1
One issue I’ve run into is that sometimes audio files later in the loop sometimes get cut short instead of playing to the end of the file. Apparently this issue can be avoided if you play the longest possible audio file first, but that doesn’t work for my experimental design. I noticed the issue a couple days ago and I am getting assistance with it here.
.