Soundboard doesn't work for players when file picker is used
Closed this issue · 0 comments
CDeenen commented
Replace the playTrack function in MaterialKeys.js with:
export async function playTrack(soundNr,play,repeat,volume){
if (play){
const trackId = game.settings.get(moduleName,'soundboardSettings').sounds[soundNr];
const playlistId = game.settings.get(moduleName,'soundboardSettings').selectedPlaylists[soundNr];
let src;
if (playlistId == 'FP'){
src = game.settings.get(moduleName,'soundboardSettings').src[soundNr];
const ret = await FilePicker.browse("data", src, {wildcard:true});
const files = ret.files;
if (files.length == 1) src = files;
else {
let value = Math.floor(Math.random() * Math.floor(files.length));
src = files[value];
}
}
else {
const sounds = game.playlists.entities.find(p => p._id == playlistId).data.sounds;
const sound = sounds.find(p => p._id == trackId);
if (sound == undefined){
activeSounds[soundNr] = false;
return;
}
src = sound.path;
}
volume *= game.settings.get("core", "globalInterfaceVolume");
let howl = new Howl({src, volume, loop: repeat, onend: (id)=>{
if (repeat == false){
activeSounds[soundNr] = false;
}
},
onstop: (id)=>{
activeSounds[soundNr] = false;
}});
howl.play();
activeSounds[soundNr] = howl;
}
else {
activeSounds[soundNr].stop();
}
}