The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

background music on homepage

2 posters

Go down

Solved background music on homepage

Post by hbox August 3rd 2015, 4:43 pm

is it possible to add background music to the homepage
avatar
hbox
New Member

Posts : 3
Reputation : 1
Language : english

Back to top Go down

Solved Re: background music on homepage

Post by Ange Tuteur August 3rd 2015, 5:19 pm

Hi @hbox,

Yes it's possible with the <audio> element. Wink

Go to Administration Panel > Modules > JavaScript codes management and create a new script.

Placement : In the homepages
Paste the following code :
Code:
$(function() {
  var audio = {
    loop : true,
    autoplay : true,
    controls : false,
   
    source : {
      mp3 : '',
      ogg : '',
      wav : ''
    }
  },
     
  node = document.createElement('AUDIO'), i, j, src;
 
  for (i in audio) {
    if (audio[i].constructor != Object) node[i] = audio[i];
    else {
      for (j in audio[i]) {
        if (audio[i][j]) {
          src = document.createElement('SOURCE');
          src.src = audio[i][j];
          src.type = 'audio/' + (j == 'mp3' ? 'mpeg' : j);
          node.appendChild(src);
        }
      }
    }
  }
 
  document.body.appendChild(node);
  'par ange tuteur';
});

There are a few things to modify :

loop : if set to true the audio will loop when it ends, otherwise set it to false so it does not loop.

autoplay : when set to true the audio will automatically play.

controls : currently set to false, but if set to true it will show the player controls.

Lastly you'll see source and inside it : mp3, ogg, and wav. Between the empty quotes you should link to the music file and place it under the correct extension. For example, if the file link ends in .mp3 it should go in the mp3 slot.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: background music on homepage

Post by hbox August 11th 2015, 11:41 pm

thanks for that  Hello
avatar
hbox
New Member

Posts : 3
Reputation : 1
Language : english

Back to top Go down

Solved Re: background music on homepage

Post by Ange Tuteur August 12th 2015, 11:27 am

You're welcome ^^

Topic archived

If you have anymore problems feel free to open a new topic. Smile
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum