/*********************************************************************** media.js ************************************************************************ Do not change this file unless it should change for all users. This file defines functions that deal with playing of video and audio ************************************************************************/ /********************************************* Function: createAudioString Indata: an array with links to the videos (hopefully same sound file in different formats) Outdata: a string with the right encoding and tags to play video in a variety of formats *********************************************/ var glob_audioID = "audioplayer"; Content.prototype.createAudioString = function(arrayWithFileNames, audioIdString){ var c = this; //Save this to check if we're on the right page later var curPageID = c.currentPageItem.pageid; var audioString = ""; //Creates the unique name of the audio id var idString = 'audioID_' + curPageID; //glob_audioID = idString; audioString += ""; //Create the script to deal with the audio object audioString += '"; return audioString; }; //Function that is triggered after the file loads (onReady - does this trigger more than once with the same audio file?) //Checks if the page the audio was started on is the same as we're currently on (prevents the sound button from appearing on the wrong page) function checkAudioBeforePlaying(audioID){ var c = content; //Get current page id var curPageID = c.currentPageItem.pageid; //Turn the page id into an audio string var currString = 'audioID_' + curPageID; //Check if the audioID(the page when the audio was connected) is the same as currString (the current page) if(audioID == currString){ showSoundButton(); } else { hideSoundButton(); stopAudio(); } } function stopAudio(){ var audioID = "audioplayer"; var playerInstance = jwplayer(audioID); if(playerInstance == null){ //No player exists. return; } try{ playerInstance.stop(); } catch(e){ if(window.console){ console.log("Error with stopAudio function: " + e); } } } function hideSoundButton(){ $("#soundBtn").css('visibility', 'hidden'); } function showSoundButton(){ $("#soundBtn").css('visibility', 'visible'); } function setupError(idString){ if(window.console){ console.log("setupError with jwplayer: " + idString); } } Content.prototype.loadAudio = function(audioObjects){ var audioID = "audioplayer"; var playerInstance = jwplayer(audioID); playerInstance.load([{ file: audioObjects, }]); playerInstance.play(); } Content.prototype.setupAudio = function(){ var c = this;//Connect to our content //Create an array with audio objects var audioDataObjects = $(".audiofile"); if(!audioDataObjects.length){ return; //We don't have any audio files here. } var audioObjects=new Array(); for(var aInd = 0; aInd < audioDataObjects.length;aInd++){ //Find the img files that have a src (these hold our audio files) audioObjects[aInd] = $(audioDataObjects[aInd]).attr("src"); } var audioID = "audioplayer"; //Check if audioplayer exists var jwPlayerObject = jwplayer(audioID); var playerExists = false; if(jwPlayerObject == null){ if(window.console){ console.log("no jwplayer audio player exists");} } else { playerExists = true; } var audioPlayer = $("#" + audioID); if(audioPlayer.length && playerExists){ //Stop playing current audio var jwPlayerObject = jwplayer(audioID); try{ jwPlayerObject.stop(); } catch(e){ if(window.console){ console.log("problem with setupAudio: " + e); } } c.loadAudio(audioObjects); } else { //If no audio player exists, create one var audiohtml = c.createAudioString(audioObjects, audioID); //attach the player to main (so that it isn't erased before play triggers) $("#at_body_container").prepend("