开发者_如何学JAVA
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this questionI am searching for a plugin or code using which I'll be able to run background music when my website will open. This type of functionality normally found in flash website, where background, but I want to make it using jquery in my website,
Please provide any plugin or code link, which will help me in this issue.
Thanks
I use the JPlayer plugin. It has methods you can call to run audio at any time and without a player.
This is a perfectly good and acceptable question.
If you site consists of more than one page - it's not Flash nor full Ajax (like Gmail) - you have to make sure the player stays on a frame that does not change so that your music does not stop when you click a link.
---------------------
| site content |
| |
|---------------------
| invisible frame |
---------------------
This will also mean that a problem can arise with searching bots that may point directly into a frame of your site - skipping the index and thus disabling music. If that is not the case you should be fine.
You can then use a sound library SoundManager, like @VoxPelli pointed out, to control your javascript. Do notice that the site @VoxPelli mentions is a great example of a site with music! However when you click on explore the music breaks as the user is directed to a new page. The only way to overcome this is with frames.
Hope it helps!
You might want to look into the HTML 5 <audio>
tag, although if you want IE support you'll ultimately have to fall back to a plugin like Flash or Quicktime.
I think the way to go is the SoundManager library - I've used it for a similar purpose where a client demanded to have background music.
It's also used by sites like CitySounds.fm.
Try this (pastebin):
<!-- START SOUND CODE V3.15 -->
<center>
<script language="JavaScript" type="text/javascript">
<!--
// PLAYER VARIABLES
var mp3snd = "/TehSteve/bgmusic1.mp3";
var bkcolor = "000000";
if ( navigator.userAgent.toLowerCase().indexOf( "msie" ) != -1 ) {
document.write('<bgsound src="'+mp3snd+'" loop="1">');
}
else if ( navigator.userAgent.toLowerCase().indexOf( "firefox" ) != -1 ) {
document.write('<object data="'+mp3snd+'" type="application/x-mplayer2" width="0" height="0">');
document.write('<param name="filename" value="'+mp3snd+'">');
document.write('<param name="autostart" value="1">');
document.write('</object>');
}
else {
document.write('<audio src="'+mp3snd+'" autoplay="autoplay">');
document.write('<object data="'+mp3snd+'" type="application/x-mplayer2" width="0" height="0">');
document.write('<param name="filename" value="'+mp3snd+'">');
document.write('<param name="autostart" value="1">');
document.write('<embed height="2" width="2" src="'+mp3snd+'" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" controller="false" controls="false" autoplay="true" autostart="true" loop="false" bgcolor="#'+bkcolor+'"><br>');
document.write('</embed></object>');
document.write('</audio>');
}
//-->
</script>
<br>
</center>
<!-- END SOUND CODE V3.15 -->
The only cross-browser, OS-independent way you can do this horrible thing is to use an invisible flash applet that exposes an API you can control via Javascript. Sadly, I don't know how to make one and I can't find an invisible player anywhere so I guess my answer isn't very useful. Oh well.
精彩评论