A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Building a kind of radio broadcast with XML

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    68

    Unhappy Building a kind of radio broadcast with XML

    hi guys...

    i´m trying to uild a kind of radio for my site, the idea is broacast from a mp3 player continuous playing but im stuck with my xml.
    what i want to do is grab a xml list, and loop the files...meaning..when they achive the end go back to beginning.
    The code im using till now is this:

    XML:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <musica>
    <music url="mixset.mp3"/>
    <music url="mixset2.mp3"/>
    <music url="mixset3.mp3"/>
    </musica>

    Flash:

    i=0;
    mNumber = 0;
    listaMP3 = new XML();
    listaMP3.ignoreWhite = true;
    listaMP3.load("playlist.xml");
    listaMP3.onLoad = function ()
    {
    _global.songfile = [];
    _global.songfile[i] = listaMP3.firstChild.childNodes[i].attributes.url;
    trace(songfile[i]);
    trilha = new Sound();
    list = listaMP3.firstChild.childNodes;
    som = list[0].attributes.url;
    trilha.loadSound(som, true)
    som.start(0, 0)
    trilha.onSoundComplete = function (){

    if (mNumber<list.length){
    mNumber++
    i++
    _global.songfile[i] = listaMP3.firstChild.childNodes[i].attributes.url;
    trace(songfile[i]);
    som = list[mNumber].attributes.url;
    trilha.loadSound(som, true);
    }
    }
    }

    What is happening is that it plays all 3 files but i cant get back to beginning, ive tryied conditions like "if" or "do whilhe" and i just cant do it...well..i can loops the first 2 files by inserting at the end of the code:

    if (trilha.onSoundComplete) { gotoAndPlay(1) }

    but this does not allows me to listten to the 3rd element of the XML list.

    what shall i do?

    Thank you:

    Duarte V.

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Let myself clear first!
    Are you want to play 1 then 2 then 3 and then back to 1 and loop?
    Or, play 1 and loop to 1 until user click to play for other from the list?


    poltuda

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    68
    Quote Originally Posted by poltuda View Post
    Let myself clear first!
    Are you want to play 1 then 2 then 3 and then back to 1 and loop?
    Or, play 1 and loop to 1 until user click to play for other from the list?


    poltuda
    first tks for replying...

    i want to play 1, 2 and 3 then loop back to 1 and play 2 ,3 then loop back again to 1 like a continuous play....

  4. #4
    Senior Member
    Join Date
    May 2010
    Posts
    178
    ActionScript Code:
    i = 0;
    listaMP3 = new XML();
    listaMP3.ignoreWhite = true;
    listaMP3.load("playlist.xml");
    listaMP3.onLoad = function() {
        _global.songfile = [];
        _global.songfile[i] = listaMP3.firstChild.childNodes[i].attributes.url;
        trace(songfile[i]);
        trilha = new Sound();
        list = listaMP3.firstChild.childNodes;
        som = list[i].attributes.url;
        trilha.loadSound(som,true);
        som.start(0,0);
        trilha.onSoundComplete = playLoop;
        trace(list.length);
    };
    function playLoop() {

        if (i<list.length-1) {
            i++;
            _global.songfile[i] = listaMP3.firstChild.childNodes[i].attributes.url;
            trace(songfile[i]);
            som = list[i].attributes.url;
            trilha.loadSound(som,true);
        } else {
            i = 0;
            _global.songfile[i] = listaMP3.firstChild.childNodes[i].attributes.url;
            trace(songfile[i]);
            som = list[i].attributes.url;
            trilha.loadSound(som,true);
        }
    }



    poltuda

  5. #5
    Member
    Join Date
    Mar 2011
    Posts
    68
    Quote Originally Posted by poltuda View Post
    ActionScript Code:
    i = 0;
    listaMP3 = new XML();
    listaMP3.ignoreWhite = true;
    listaMP3.load("playlist.xml");
    listaMP3.onLoad = function() {
        _global.songfile = [];
        _global.songfile[i] = listaMP3.firstChild.childNodes[i].attributes.url;
        trace(songfile[i]);
        trilha = new Sound();
        list = listaMP3.firstChild.childNodes;
        som = list[i].attributes.url;
        trilha.loadSound(som,true);
        som.start(0,0);
        trilha.onSoundComplete = playLoop;
        trace(list.length);
    };
    function playLoop() {

        if (i<list.length-1) {
            i++;
            _global.songfile[i] = listaMP3.firstChild.childNodes[i].attributes.url;
            trace(songfile[i]);
            som = list[i].attributes.url;
            trilha.loadSound(som,true);
        } else {
            i = 0;
            _global.songfile[i] = listaMP3.firstChild.childNodes[i].attributes.url;
            trace(songfile[i]);
            som = list[i].attributes.url;
            trilha.loadSound(som,true);
        }
    }



    poltuda
    VERY MUCH THANKS

    it works perfectly..im not using the:

    trace (list.length)

    it works anyway but is it necessary?
    im not using it cause i might have to grab the output data to display the names in the "radio".....

    Thanks Again!

    Duarte V.

  6. #6
    Senior Member
    Join Date
    May 2010
    Posts
    178
    trace is for debugging purpose. I put it to show that the length is 3 of the xml node and for that you have to loop from length - 1.

    One change will be a good standard in xml.

    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <musica>
            <music>
                   <musicTitle>Title 1</musicTitle>
                   <musicDes>Description</musicDes>
                   <musicURL>mp3/mixset1.mp3</musicURL>
            </music>
            <music>
                   <musicTitle>Title 2</musicTitle>
                   <musicDes>Description</musicDes>
                   <musicURL>mp3/mixset2.mp3</musicURL>
            </music>
            <music>
                   <musicTitle>Title 3</musicTitle>
                   <musicDes>Description</musicDes>
                   <musicURL>mp3/mixset3.mp3</musicURL>
            </music>
    </musica>

    poltuda

  7. #7
    Senior Member
    Join Date
    May 2010
    Posts
    178
    ActionScript Code:
    <?xml version=1.0 ?>
    <rss version="0.91">
    <channel>
      <!-- Required elements -->
      <title></title>             <!-- Maximum length is 100 characters. -->
      <link></link>               <!-- A URL pointing to the website named in the <title>. Maximum length is 500 characters. -->
      <description></description> <!-- Maximum length is 500 characters. -->
      <language></language>
      <image>
        <!-- required elements -->
        <url></url>     <!-- The URL of a GIF, JPEG or PNG image that represents the channel. Maximum length is 500. -->
        <title></title> <!-- Describes the image. Used in the ALT attribute of <img> tag when the channel is rendered in HTML. Maximum length is 100. -->
        <link></link>   <!-- URL of the site, when the channel is rendered, the image is a link to the site. (Note, in practice the image <title> and <link> should have the same value as the channel&apos;s <title> and <link>. Maximum length is 500. -->

        <!-- optional elements -->
        <width>88</width>           <!-- Maximum value for width is 144, default value is 88. -->
        <height>31</height>         <!-- Maximum value for height is 400, default value is 31. -->
        <description></description> <!-- contains text that is included in the TITLE attribute of the link formed around the image in the HTML rendering. -->
      </image>

      <!-- Optional elements -->
      <copyright></copyright>           <!-- Maximum length is 100. -->
      <managingEditor></managingEditor> <!-- The email address of the managing editor of the channel, the person to contact for editorial inquiries. Maximum length is 100. The suggested format for email addresses in RSS elements is [email]bull@mancuso.com[/email] (Bull Mancuso). -->
      <webMaster></webMaster>           <!-- Maximum length is 100. -->
      <rating></rating>                 <!-- The PICS rating for the channel. Maximum length is 500. -->
      <pubDate></pubDate>               <!-- The publication date for the content in the channel. For example, the New York Times publishes on a daily basis, the publication date flips once every 24 hours. That&apos;s when the pubDate of the channel changes. All date-times in RSS conform to the Date and Time Specification of RFC 822. -->
      <lastBuildDate></lastBuildDate>   <!-- The date-time the last time the content of the channel changed. -->
      <docs>http://backend.userland.com/rss091</docs> <!-- A URL, points to the documentation for the format used in the RSS file. It&apos;s probably a pointer to this page. It&apos;s for people who might stumble across an RSS file on a Web server 25 years from now and wonder what it is. Maximum length is 500. -->
      <textInput>                       <!-- An XML element that contains several sub-elements. -->
        <!-- required sub-elements. -->
        <title></title>                 <!-- The label of the Submit button in the text input area. Maximum length is 100. -->
        <description></description>     <!-- Explains the text input area. Maximum length is 500. -->
        <name></name>                   <!-- The name of the text object in the text input area. Maximum length is 20.-->
        <link></link>                   <!-- The URL of the CGI script that processes text input requests. Maximum length is 500. -->
      </textInput>

      <skipDays></skipDays>             <!-- An XML element that contains up to seven <day> sub-elements whose value is Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday. Aggregators may not read the channel during hours listed in the skipDays element. (Most aggregators seem to ignore this element.) -->
      <skipHours></skipHours>           <!--An XML element that contains up to 24 <hour> sub-elements whose value is a number between 1 and 24, representing a time in GMT, when aggregators, if they support the feature, may not read the channel on days listed in the skipHours element. (Most aggregators seem to ignore this element.) -->

      <!-- Item element this maybe repeated as many times as desired -->
      <!-- A channel may contain any number of items, each of which links to a -->
      <!-- story, with an optional description. -->
      <item>
        <title></title>             <!-- Title of the story. Maximum length is 100. -->
        <link></link>               <!-- URL of the story. Maximum length is 500. -->
        <description></description> <!-- Story synopsis. Maximum length is 500. -->
      </item>

    </channel>
    </rss>



    you can follow this rss format in future.


    poltuda
    Last edited by poltuda; 07-27-2011 at 02:56 PM.

  8. #8
    Member
    Join Date
    Mar 2011
    Posts
    68

    Thumbs up

    Quote Originally Posted by poltuda View Post
    ActionScript Code:
    <?xml version=1.0 ?>
    <rss version="0.91">
    <channel>
      <!-- Required elements -->
      <title></title>             <!-- Maximum length is 100 characters. -->
      <link></link>               <!-- A URL pointing to the website named in the <title>. Maximum length is 500 characters. -->
      <description></description> <!-- Maximum length is 500 characters. -->
      <language></language>
      <image>
        <!-- required elements -->
        <url></url>     <!-- The URL of a GIF, JPEG or PNG image that represents the channel. Maximum length is 500. -->
        <title></title> <!-- Describes the image. Used in the ALT attribute of <img> tag when the channel is rendered in HTML. Maximum length is 100. -->
        <link></link>   <!-- URL of the site, when the channel is rendered, the image is a link to the site. (Note, in practice the image <title> and <link> should have the same value as the channel&apos;s <title> and <link>. Maximum length is 500. -->

        <!-- optional elements -->
        <width>88</width>           <!-- Maximum value for width is 144, default value is 88. -->
        <height>31</height>         <!-- Maximum value for height is 400, default value is 31. -->
        <description></description> <!-- contains text that is included in the TITLE attribute of the link formed around the image in the HTML rendering. -->
      </image>

      <!-- Optional elements -->
      <copyright></copyright>           <!-- Maximum length is 100. -->
      <managingEditor></managingEditor> <!-- The email address of the managing editor of the channel, the person to contact for editorial inquiries. Maximum length is 100. The suggested format for email addresses in RSS elements is [email]bull@mancuso.com[/email] (Bull Mancuso). -->
      <webMaster></webMaster>           <!-- Maximum length is 100. -->
      <rating></rating>                 <!-- The PICS rating for the channel. Maximum length is 500. -->
      <pubDate></pubDate>               <!-- The publication date for the content in the channel. For example, the New York Times publishes on a daily basis, the publication date flips once every 24 hours. That&apos;s when the pubDate of the channel changes. All date-times in RSS conform to the Date and Time Specification of RFC 822. -->
      <lastBuildDate></lastBuildDate>   <!-- The date-time the last time the content of the channel changed. -->
      <docs>http://backend.userland.com/rss091</docs> <!-- A URL, points to the documentation for the format used in the RSS file. It&apos;s probably a pointer to this page. It&apos;s for people who might stumble across an RSS file on a Web server 25 years from now and wonder what it is. Maximum length is 500. -->
      <textInput>                       <!-- An XML element that contains several sub-elements. -->
        <!-- required sub-elements. -->
        <title></title>                 <!-- The label of the Submit button in the text input area. Maximum length is 100. -->
        <description></description>     <!-- Explains the text input area. Maximum length is 500. -->
        <name></name>                   <!-- The name of the text object in the text input area. Maximum length is 20.-->
        <link></link>                   <!-- The URL of the CGI script that processes text input requests. Maximum length is 500. -->
      </textInput>

      <skipDays></skipDays>             <!-- An XML element that contains up to seven <day> sub-elements whose value is Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday. Aggregators may not read the channel during hours listed in the skipDays element. (Most aggregators seem to ignore this element.) -->
      <skipHours></skipHours>           <!--An XML element that contains up to 24 <hour> sub-elements whose value is a number between 1 and 24, representing a time in GMT, when aggregators, if they support the feature, may not read the channel on days listed in the skipHours element. (Most aggregators seem to ignore this element.) -->

      <!-- Item element this maybe repeated as many times as desired -->
      <!-- A channel may contain any number of items, each of which links to a -->
      <!-- story, with an optional description. -->
      <item>
        <title></title>             <!-- Title of the story. Maximum length is 100. -->
        <link></link>               <!-- URL of the story. Maximum length is 500. -->
        <description></description> <!-- Story synopsis. Maximum length is 500. -->
      </item>

    </channel>
    </rss>



    you can follow this rss format in future.


    poltuda
    ok! thank you very much..realy apreciated your help..ill try the rss this night Very much for your help .. if i can be used in something just contact me at www.thebeastpost.com ....<- music is my "art" case you want some tracks

    Regards:

    Duarte V.

Tags for this Thread

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center