0

Possible Duplicate:
Integrate a mp3 player into a page with no reloading issue

I have a website of 10 webpages and I want to insert an automatic playing song in this site.

However I want that when I click on another webpage of this site then the music doesn't stop.

Is this a way to do this without using iframe or flash ?

Community
  • 1
  • 1
xRobot
  • 25,579
  • 69
  • 184
  • 304
  • 8
    I don't know, how this can be achived, I can only advise you to not play any music: it's simply annoying... – eckes Dec 26 '10 at 12:53
  • Here's another dupe with more details: http://stackoverflow.com/questions/2205021/can-you-make-an-embedded-mp3-keep-playing-from-where-it-left-off – Pekka Dec 26 '10 at 12:55
  • 4
    Background music on websites is *so* 1995... – Michael Borgwardt Dec 26 '10 at 13:01
  • Even if I must agree with both comments advising "please, don't do that", I had, once, to do such a thing. I successed by using a jquery player and a flash plugin (to read mp3) and recorded the time in a cookie, when you go to another page, the music is played back exactly where it stopped on the previous page. – Boris Guéry Jan 30 '11 at 23:21

2 Answers2

2

EDIT: I did not read your question fully. Unless you are using frames or Ajax for navigation (as in Gmail or New Twitter), this is not possible.

Old method

<BGSOUND SRC="aladdin.mid" LOOP=10>

Or use HTML 5

<audio autoplay id="bgsound">
 <source src="http://media.w3.org/2010/07/bunny/04-Death_Becomes_Fur.mp4"
         type="audio/mp4">
 <source src="http://media.w3.org/2010/07/bunny/04-Death_Becomes_Fur.oga"
         type="audio/ogg; codecs=vorbis">
 <p>Your user agent does not support the HTML5 Audio element.</p>
</audio>
<button type="button"
        onclick="document.getElementById('bgsound').pause();">
  Stop background sound
</button>

<p>
You'll probably annoy your readers if you use background sounds in documents.
</p>
Joyce Babu
  • 19,602
  • 13
  • 62
  • 97
1

First of all: don't start play music automatically on a webpage, let the user decide about to start the music or not.

You should put all your webpages into a long webpage, each one into a DIV:

<div id="page1">
 content of page 1
</div>
<div id="page2" style="display: hidden">
 content of page 2
</div>
<!-- etc. -->

Except the first one, hide the divs by CSS or style tag, see example. Then all the links pointing to other pages should call a small javascript code, which changes the visibility of the divs, turning the "referenced" one visible and hide others:

<a href="#" onclick="switchToPage(2)"> go to page 2 </a>

The player should be placed before the divs, or anywhere. The advantage of this method, that you may make a fix footer, header etc., and change only the content area. The disadvantage is that search engines will only see a long page instead of 10.

But again: don't make a webpage which starts playing music automatically!

ern0
  • 3,074
  • 25
  • 40