views:

40

answers:

2

Hi,

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.

A: 

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.

James Black
A: 

Hi James,

First of all, thank you for your answer.

1) If you have a minute, check the link I have posted before which contains the script files. The javascript is here http://www.dynamicdrive.com/dynamicindex2/ajaxticker.js

Note that in my case the tickercontent.txt file doesn´t have any XML code, just plain text formatted as [DAY-MONTH-YEAR HOUR:MIN:SEC] * Artist - Track

2) The use for this application is to show the track names in realtime in a big projector screen connected to the computer. I want to run the script locally, within an Apache server running in Mac. I am using a third party freeware application (Metadata Listener) that fetches the mp3 tags from the mp3 player to a .log file updated each time and saved into the /Users folder. Running that script locally in Apache, I can get the data from the .log file locally too.

3) I have answer your third question before. It is on the local computer.

So I have a .log file that saves each song in the format [DAY-MONTH-YEAR HOUR:MIN:SEC] * Artist - Track and I want to show each song while it´s playing in a screen, for multimedia purposes.

Hope this helps to understand what I need.

Thank you again.

Pablo