Forum Moderators: open
I have created a page that extracts from a database 2 value one being the duration of a song in millisecs, the other being the date and time that the song started playing. At the moment the "spry" updates every 30 secs so as a new song is played it roughly falls in that the new data is displayed which is fine all good... however what i would like to do is display a count down of where the track in time in minutes and secs from the calculation i believe to be duration minus (date_played-Now())and ticking down on the page, at the end of the song i would like it to refresh the spry data extractor code.
my page being this...
[<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:spry="http://ns.adobe.com/spry">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="SpryAssets/xpath.js" type="text/javascript"></script>
<script src="SpryAssets/SpryData.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
var now_playing = new Spry.Data.XMLDataSet("/controllers/now_playing.asp", "export/row",{distinctOnLoad:true,useCache:false,loadInterval:30000});
//-->
</script>
</head>
<body>
<div spry:region="now_playing">
<p>Artist Name = {artist}</p>
<p>Track Title = {title}</p>
<p>Album Name = {album}</p>
<p>Song ID = {songID}</p>
<p><img src="http://pictures.example.co.uk/covers/Unsigned/{artist}/{album}/front.jpg" name="pic111" id="pic111" /></p>
<p>Time and date played ={date_played}</p>
<p>Track length = ms {duration}</p>
<p>Time and date Now =
<%response.Write(Now())%>
</p>
<p> </p>
</div>
</body>
</html>]
...sorry i originally posted a link and then read there not allowed :) sorry again... to show what i have so far any help and or advice would be greatly appreciated.
Regards
Ray(hankypark)
[edited by: whoisgregg at 5:57 pm (utc) on Aug. 4, 2009]
[edit reason] Exemplified image URL. :) [/edit]
var myObserver = new Object;
myObserver.onDataChanged = function(dataSet, data)
{
// If this alert works, then you can add code in here to calculate time offsets and update the DOM
alert("onDataChanged called!");
};
now_playing.addObserver(myObserver);
If you can get that alert to fire at the right time, then the rest shouldn't be too hard. Post back if you have more questions or run into trouble with this code. :)
Ok will start reading up on the above you mentioned though my original thoughts were that if the dataset is called without a refresh interval when the page loads then by using javascript and the values retrieved it might be possible to have a count down timer display next to the song:to the end of the song so that when at zero it could then go and get fresh data at that point.
I could be thinking about this all wrong but i am a mere amatuer :)
Regards
Ray(hankypark)
I could maybe do with a litte more help if you please, basically what i have done is put the observer in place and it now triggers a data refresh when the page first load which then sets the interval timer to refresh, the period being the duration field value from the dataset, this works absolutely fine and have left the alert in place so i can catch the refresh working whilst testing as you can see below...
[<script type="text/javascript">
<!--
var now_playing = new Spry.Data.XMLDataSet("/controllers/now_playing.asp", "export/row",{distinctOnLoad:true,useCache:false});
var myObserver = new Object;
myObserver.onPostLoad = function(dataSet, data)
{
var rows = now_playing.getData();
var mydura = rows[0]["duration"];
alert("The time is the duration to next refresh " + mydura);
now_playing.startLoadInterval(mydura); // Start loading data every mydura seconds.
};
now_playing.addObserver(myObserver);
//-->
</script>
]
The refresh is falling out of sync which would be obvious as each song is different in length and depending when the pages opens determines the data refresh given the duration, so i have tried for a few days to get my head round how to work out this equation...
The length of the songs is in millisecs as in mydura = 238908, the dataset also tells me the date and time the songs started as in myplayed = 13/08/2009 12:01:08 and my thought is to take the date and time of the server when the page loads and i should be able to discover how long is left to play on the song and use that as the trigger time to next refresh. sound easy? no its not lol :) i have tried all sorts of given equations for time and date differences but i can't get the dam thing to work it out properly...
Could you help please?
Many thanks in advance
Regards
Ray
One thing you could do is try to preload the next song, so on initial page load it actually grabs two files. Then on each interval, you play the file that was loaded last and initiate the download of the next file.
I very much appreciate having someone to bounce the ideas around on and am enjoying the learning curve even I don't end up with a resolve, many thanks
Regards
Ray