Forum Discussion

KenRyu's avatar
KenRyu
Community Member
4 months ago

Some Javascripts are unable to start after uploading to Moodle

I'm using Storyline 3, published my e-learning as a SCORM 1.2 package, and I'm using a BGM by adding this code to story.html and index_lms.html :
<audio src="elearnsong.m4a" id="bgSong" preload="auto" autoplay loop></audio>

I also added the codes to my storyline like this (and sets it to "When Timeline Starts" :
var audio = document.getElementById('bgSong');
audio.src="elearnsong.m4a";
audio.load();
audio.play();

Then this code so I can use it for Volume Control, same start :
var player = GetPlayer();
var level = player.GetVar("volume")
var audio = document.getElementById('bgSong');
audio.volume = level;

And this is for the volume control for every sound (BGM, SFX, and Voice Overs) :
var player = GetPlayer();
var volume = player.GetVar("volume");
function adjustVolume() {
  var mediaElements = document.querySelectorAll('audio, video');
  mediaElements.forEach(function(element) {
    volume = Math.max(0, Math.min(10, volume));
    var adjustedVolume = volume / 10;
    element.volume = adjustedVolume;
    element.muted = (volume === 0);
  });
}
adjustVolume();

I'm not really fluent with Javascript, so I don't know what went wrong. It works fine when I tried it by checking story.html locally, but when I uploaded it to Moodle (and I assume they used the index_lms.html) my src and volume got an error, it says Can't set properties to null. 

I put the elearnsong.m4a on the root of the directory as well, I don't know what's wrong. Can you guys help me? :')

No RepliesBe the first to reply