views:

107

answers:

3

Is it possible to make an mp3, that is embedded in a webpage, keep playing from where it left off if the page is reloaded? Perhaps into a cookie or with any other method.

<embed src="track1.mp3"></embed>

For example:

track1.mp3 is embedded in a webpage; it is 3 minutes long. A visitor loads the webpage and listens to the first 1 minute and 25 seconds of the track; then closes the webpage. Can I make track1.mp3 start playing from 1 minute and 25 seconds the next time that person visits the webpage?

A: 

how is it embedded? With just html?...probably not. If you are using Flash, then yes, you could keep track of the bytes, and write to a session or cookie.

You might need to expound on your question a little, ie, what is the process that you are using.

Senica Gonzalez
A: 

I don't know of anyway to do this other than with Actionscript. I can't think of any Javascript methods that would allow you to access an embedded object like that. My recommendations for this would be to do it with Flash. If you don't have access to it, you can do it with Flex, which the SDK is free to download from Adobe.

HTML5 specifications have some promising new features for handling video and audio. I have not paid that much attention to that portion of it yet. I really don't think you are going to find a quick answer to this one.

Senica Gonzalez
+1  A: 

I have seen one Flash-based MP3 player providing an approach to do this, with only a minimal disruption when switching between pages, but can't for the life of me find the project with any search term that comes to mind. (The big word was "seamless playback"). Anyway, it was a discontinued project, the last update being sometime in 2006 so it wouldn't probably be much use on the long term.

But nowadays, with every man and their dog having a JavaScript-enabled browser, maybe changing your page's architecture to making it fetch new pages using Ajax is the better approach. It can be made degrade gracefully for non-JS browsers, and would allow for seamless playing without any tricks for JavaScript users (because the page is never reloaded).

See discussion about the pros and cons of the approach here: Why not just using ajax for Page Requests to load the page content?

And some pointers how to get started: JQuery/AJAX: Loading external DIVs using dynamic content

Pekka