Results 1 to 6 of 6

Thread: Ajax XML Ticker, with plain .txt?

  1. #1
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ajax XML Ticker, with plain .txt?

    1) Script Title: Ajax XML Ticker (txt file source)

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...ajaxticker.htm

    3) Describe problem:

    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:

    Code:
    [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 the Ajax XML Ticker (txt file source) 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.


    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.
    Last edited by pibo; 07-25-2010 at 11:51 PM.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Are you able to edit the format of your .txt file so it conforms to that used by the Ticker Script, or:

    Code:
    <div>
    
    <div class="message">
    [24-07-2010 20:17:11] * Song 1
    </div>
    
    <div class="message">
    [24-07-2010 20:21:11] * Song 2
    </div>
    
    <div class="message">
    [24-07-2010 20:25:18] * Song 3
    </div>
    
    <div class="message">
    [24-07-2010 20:29:58] * Song 4
    </div>
    
    </div>
    This will get the script to rotate these messages one by one.

    To the other part of your question, are you essentially asking how to always show the latest ticker message (the very 1st one), instead of rotating between the messages?
    DD Admin

  3. #3
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi ddadmin,

    Thanks for your answer.

    To your 1st question, I had said in my post that "this formatted text file cannot be changed", thatīs the big issue here, it comes this way directly from the software that gets the ID3 tags from the played songs in real time, and it is autoupdated each time a new track starts playing. I am searching for a script or something that converts formatted text to xml in real time, but I havenīt found it yet (I donīt know if it is possible to do). The thing here is that you have the "*" like a "pseudo-class" at the beginning of each message, I donīt know if it is enough to send the data to the div and show it somehow.

    To your 2nd question: yes.

    Thank you very much.
    Last edited by pibo; 07-27-2010 at 12:28 PM.

  4. #4
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Sorry I missed that. Well, you can convert regular text contents fetched via Ajax, say:

    Code:
    [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 ...
    into a JavaScript array, which each line stored as an array element. Lets say "page_request.responseText" is the returned Ajax object that contains the raw contents of your text file- to transform that into an array of contents, you'd do:
    Code:
    var messages=page_request.responseText.split("\n")
    Now messages[0] contains "[24-07-2010 20:17:11] * Song" for example.

    With that said, and using a modified version of Ajax Includes Script, the below displays the 1st line of your text file each time the page is loaded:

    Code:
    <script type="text/javascript">
    
    /***********************************************
    * Ajax Includes script- Đ Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    var rootdomain="http://"+window.location.hostname
    
    function ajaxinclude(url) {
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
    try {
    page_request = new ActiveXObject("Msxml2.XMLHTTP")
    } 
    catch (e){
    try{
    page_request = new ActiveXObject("Microsoft.XMLHTTP")
    }
    catch (e){}
    }
    }
    else
    return false
    page_request.open('GET', url+"?bustcache="+new Date().getTime(), false) //get page synchronously 
    page_request.send(null)
    writecontent(page_request)
    }
    
    function writecontent(page_request){
    if (window.location.href.indexOf("http")==-1 || page_request.status==200){
    var messages=page_request.responseText.split("\n")
    document.write(messages[0])
    }
    }
    
    </script>
    
    <body>
    
    <script type="text/javascript">
    ajaxinclude("tickercontent.txt")
    </script>
    Be sure to change tickercontent.txt to the name of your text file.
    DD Admin

  5. #5
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi again ddadmin,

    Thanks for your work! I have copied your code to my index.html, it works, but not in the expected way, let me tell you why.

    1. I didnīt explain it sorry. The log file have 2 introductory lines (it doesnīt matter, because when the 3rd is loaded they should be hidden in the web page), but the most important thing as you can see (check the dates), is that the log file creates the new entries from the 3rd line to the bottom, not at the top of the file, so the first line is always the same. The new lines are placed at the bottom:

    Code:
    [24-07-2010 20:08:45] Log file created for client "127.0.0.1,50021".
    [24-07-2010 20:08:45] Client "127.0.0.1,50021" connected.
    [24-07-2010 20:17:11] * Artist 1 - Song 1
    [24-07-2010 20:21:11] * Artist 2 - Song 2
    ...
    2. I would like to show just the "Artist - Song" text, avoiding the [DAY-MONTH-YEAR HOUR:MIN:SEC] * part (in other words, showing the text from the *, or the 25th character of the line). Can it be done?

    3. Another thing is that the script doesnīt autoupdate the page when a new song comes from the log file. You need to refresh the page manually for showing the new tracks (I have tested it in Safari and Firefox, typing another text lines at the top of my tickercontent.txt file)

    4. Finally, could this script be implemented with the Ajax XML Ticker look? I like the way Ajax XML Ticker shows the posts.


    Thank you so much.
    Last edited by pibo; 07-27-2010 at 07:36 PM.

  6. #6
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Lets take this one step at a time. Inside the above modified script, find the below line of code:

    Code:
    document.write(messages[0])
    and replace that with:

    Code:
    var targetmessage=messages[2].substr(22)
    document.write(targetmessage)
    This should display the 3rd message within the text file, and skip the "[24-07-2010 20:21:11]" portion of the line.
    DD Admin

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •