Bonsoir, j'ai cherché sur le forum et le net en long et en large et rien...
Je veux tout simplement faire ce que tout le monde veux faire, avoir une musique qui débute à l'ouverture de la page et pouvoir la couper à ma guise...
j'ai essayé avec du javascript (code trouvé sur un forum anglais : voir source ds le code en question) mais je ne m'y connais absolument pas :
voilà ce que cela donne :
Code Javascript :
<script type="text/javascript">
/*Toggle Sound Script III ©2008 John Davenport Scheuer
as first seen in www.dynamicdrive.com/forums (user name:
jscheuer1). Visit http://www.dynamicdrive.com for 100's
of DHTML scripts. This credit must remain for legal use.
*/
var sndEl="sound/back.mp3" //Set to name and path of your sound file
var music_on="sound/on.gif" //Set to image to display while music is on
var music_off="sound/off.gif" //Set to image to display while music is off
var active_img="sound/onair.gif" //Set to image to display while image is hovered
///////////////Stop Editing///////////////
var mpIsInstalled = false;
if (window.ActiveXObject) {
var control = null;
/*@cc_on @*/
/*@if(@_jscript_version >= 5)
try {
control = new ActiveXObject('WMPlayer.OCX');
} catch (e) {}
@end @*/
if (control&&control.versionInfo) {
mpIsInstalled = true;
}
}
var da=document.all
var preload=[music_on, music_off, active_img]
var preloading=new Array();
for (var i_tem = 0; i_tem < preload.length; i_tem++){
preloading[i_tem]=new Image();
preloading[i_tem].src=preload[i_tem]
}
function textReveal(el, state){
var text=da? da.text : document.getElementById('text')
text.style.visibility=state=='on'? 'visible' : ''
el.src=state=='on'? active_img : el.lowsrc
}
function toggleSound(el){
var text=da? da.text : document.getElementById('text')
if(mpIsInstalled){
if(text.innerHTML==' Music Off'){
toggleSound.p=sound.controls.currentPosition;
sound.controls.stop();
el.lowsrc=music_off;
text.innerHTML=' Music On';
}
else{
sound.URL=sndEl;
if(toggleSound.p)
sound.controls.currentPosition=toggleSound.p;
el.lowsrc=music_on;
text.innerHTML=' Music Off';
}
}
else if (da&&da.sound&&(da.sound.src!==''||!toggleSound.l)){
toggleSound.l=true;
da.sound.src=''
el.lowsrc=music_off
text.innerHTML=' Music On'
}
else if (document.getElementById('snd')){
sndEl=document.getElementById('snd')
document.getElementById('sndC').removeChild(sndEl)
el.lowsrc=music_off
text.innerHTML=' Music On'
}
else if (da&&da.sound&&da.sound.src==''){
da.sound.src=sndEl
el.lowsrc=music_on
text.innerHTML=' Music Off'
}
else {
document.getElementById('sndC').appendChild(sndEl)
el.lowsrc=music_on
text.innerHTML=' Music Off'
}
}
onload=function(){toggleSound(document.images.bob);
if(document.getElementById&&document.getElementById('sndC'))
document.getElementById('sndC').style.display='';};
</script>
Code HTML :
<script type="text/javascript">
if (document.getElementById&&!document.getElementById('sound')){
document.write('<div id="sndC" style="width:0;height:0;position:absolute;top:-1000px;left:-1000px;visibility:hidden;display:none;">')
document.write('<embed id="snd" type="audio/wav" style="width:0;height:0;position:absolute;top:-1000px;left:-1000px;visibility:hidden;" src="'+sndEl+'" autostart="true" hidden="true" loop="true">')
document.write('<\/div>')
}
if ((da&&da.sound)||document.getElementById)
document.write('<img id="bob" name="bob" style="cursor:pointer;" lowsrc="'+music_on+'" src="'+music_off+'" onmouseout="textReveal(this, \'off\')" onmouseover="textReveal(this, \'on\');" onclick="toggleSound(this);"><span id="text"> Music Off<\/span>')
</script>
<!-- End Toggle Sound Body Code -->
Et voilà ce que celà donne sur mon site :
Tapez le texte de l'url ici.
Les boutons sont bien là mais pas de son. Le fichier s'appelle bien back, est bien en mp3 et se trouve bien dans le dossier sound.
Merci d'avance pour votre aide.