开发者

Ajax "ticker" from plain txt (not XML)

I am looking for a solution just to show in a html page the name of each song when played from a mp3 player.

I just have a .txt file outputted from a software that fetches in real time each song artist and name from the mp3 tag, when a new song is being played, with this format inside (the .txt file is also autoupdated each time, like a log file does):

[DAY-MONTH-YEAR HOUR:MIN:SEC] * Artist - Track

Example:

[24-07-2010 20:17:11] * Song 1
[24-07-2010 20:21:11] * Song 2
[24-07-2010 20:25:18] * Song 3
[24-07-2010 20:29:58] * Song ...

I need to get this data from the .txt file and put it into a html div, showing the new song name when it has been logged into the file until a new song is played.

Pretty simple I think, but I don´t know how to work with this formatted text file (it cannot be changed), instead a typical XML file.

I have founded a script that works with XML (not plain text) and the behavior is other than I expect, because it rotates the messages each 5 seconds, not just when the new song is playing:

http://www.dynamicdrive.com/dynamicindex2/ajaxticker.htm

  1. How can I get the [DAY-MONTH-开发者_开发百科YEAR HOUR:MIN:SEC] * formatted items in javascript?

  2. How can I update the html div, each time a new item (song) is loaded in the .txt file?

Thanks in advance for your help.


There are several pieces of your architecture missing, which makes it difficult to answer your question.

  1. Where did the javascript page come from?
  2. What is the connection to the server that the javascript comes from and the mp3 player?
  3. Where is the text file, on a server or updated on the local computer by the mp3 player?

But, if I make several assumptions you might get on the more correct path.

First, if the mp3 player sends a message to a server, and the server updates the text file (big assumption) then what you can do it to either have the javascript application poll the server on some timed basis, to decide when the song changes, and the server can just return the current song.

Is there is reason the javascript application needs the entire text file?

The other option is to have the server open up a long-term connection, such as comet (http://en.wikipedia.org/wiki/Comet_%28programming%29), and the server can just push the data to the javascript application.

I am not answering your question about how to parse the formatted file, as I don't see yet that that would actually be useful to your problem, but as I mentioned, there are too many unknowns in your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜