Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to add a catalog songlist to xml music player AS3

New Here ,
Dec 08, 2015 Dec 08, 2015

I am new to actionscript 3.0 and working on an xml driven music player. I have a playlist already but I want to incorporate a catalog list to the player. I want to be able to add songs from the catalog list to the xml playlist which will automatically add the songs to the xml database. Ive search all over for tutorials that I might can learn from but no luck. If there’s anybody out there than can give me some insight I would gratefully appreciate the help thank you. here is the xml code I’m working with.

public class MusicPlayer extends MovieClip {

  private var _xmlmp3:XML;//holder all document from xml

  private var _index_song:Number = 0;//This will be index for the xml document

  private var _sound:Sound;//we need it to stream the sound mp3

  private var _sound_position:Number = 0;//we always must know the sound position

  private var _soundchannel:SoundChannel;//we need also for streaming(volume, pause, play ....)

  private function get _url_mp3_current():String{return this._xmlmp3.song[this._index_song].@url;}//song current url

  private function get _artist():String{return this._xmlmp3.song[this._index_song].@artist;}//song artist

  private function get _songName():String{return this._xmlmp3.song[this._index_song].@songName;}//song artist

  private var _sound_volume:Number = 0.5;

  private var _sound_volume_last:Number = 0.5;

  private var _sound_panning:Number = 0;

  private var _shuffle:Boolean = false;

  //private var bytes:ByteArray = new ByteArray();

        //private var Sprite:Sprite = new Sprite();

        //this.stage.addChild(Sprite);

  public function MusicPlayer() {

  //adding event when the flash content is added to stage first frame

  this.addEventListener(Event.ADDED_TO_STAGE, ADDED_TO_STAGE);

  }

  //adding event when the flash content is added to stage first frame

  //function

  private function ADDED_TO_STAGE(e:Event)

  {

  //init loading xml file for the songs

  this.load_xml_file_for_the_songs();

  }

  private function load_xml_file_for_the_songs()

  {

  trace("load_xml_file_for_the_songs");

  /*

  we need url loader for loading the xml file

  */

  var xml_loader:URLLoader

  =

  new URLLoader(  );//we create new object instacence of URLLoader

  xml_loader.addEventListener(Event.COMPLETE, xml_loader_COMPLETE_LOADING);//we add the event

  xml_loader.load(

  new URLRequest("PlayList.xml")//this object is urlrequest

  );//after that we load the file

  //myList.rowHeight = 22;

  var textStyle:TextFormat = new TextFormat();

        textStyle.size = 12;

        textStyle.font = "Arial";

        textStyle.color = "0XFFCC00";

  myList.setRendererStyle("textFormat", textStyle);

  }

  //this is event after loading the file

  //it is holding the data for the xml player list

  private function xml_loader_COMPLETE_LOADING(e:Event)

  {

  //trace(e.target.data);//just testing

  this._xmlmp3 = new XML( e.target.data );//we create xml for flash from text source xml e.target.data

  trace( this._xmlmp3 );//just testing

  trace( this._xmlmp3.song[0].@url );

  //for loop for listing all song items from XML

  for(var iitemxml=0;iitemxml<this._xmlmp3.song.length();iitemxml++)

  {

  trace( this._xmlmp3.song[iitemxml].@songName );

  myList.addItem(

    {

    data:this._xmlmp3.song[iitemxml],//with this object item of the select box will hold xml item for the song

    label:this._xmlmp3.song[iitemxml].@songName//with this item we add label for each item of the list

    });//ading item to combox box named "myList"

  }

  this.add_events_to_the_controls();//we are adding to the controls

  /**/

  }

TOPICS
ActionScript
820
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2015 Dec 08, 2015

is that code working?  (ie, the trace output is what you expect?)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 08, 2015 Dec 08, 2015

Yes that code works, Im trying to add to it

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2015 Dec 08, 2015

other than saying you want to add a 'catalog' list can you explain what you want to add that's not already present?

actually, showing a snippet from your current xml and then showing how you want to change that, might be sufficient.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 08, 2015 Dec 08, 2015

This is how I can explain what Im trying to do. I want 2 separate lists, a catalog of songs and a playlist. the catalog list will hold all songs and the playlist will just have the songs which has been added to the playlist from the catalog. The code I have only displays the playlist. Thank you for the response much appreciated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2015 Dec 08, 2015

have you created the catalog xml?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 08, 2015 Dec 08, 2015

yes I tried but wasn't able to populate both list.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2015 Dec 08, 2015

show your catalog.xml file

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 08, 2015 Dec 08, 2015

here's a copy of xml file

<?xml version="1.0" encoding="UTF-8"?>

<catalog>

    <song url="PlayList/Triumph.mp3" songName="Triumph" artist="WuTang Clan" />

    <song url="PlayList/Born To Roll.mp3" songName="Born To Roll" artist="Master Ace" />

    <song url="PlayList/Stop Look Listen.mp3" songName="Stop Look Listen" artist="Mc Lyte"/>

    <song url="PlayList/Times Up.mp3" songName="Times Up" artist="OC" />

    <song url="PlayList/Step Into A World.mp3" songName="Step Into A World" artist="KRS1" />

    <song url="PlayList/Lauren Hill - The Miseducation of Lauryn Hill - 02 Lost Ones" songName="Lauren Hill - The Miseducation of Lauryn Hill - 02 Lost Ones" artist="Lauren Hill" />

    <song url="PlayList/Hold It Now Hit It.mp3" songName="Hold It Now Hit It" artist="Beasty Boys" />

    <song url="PlayList/Throw Them Bows.mp3" songName="Throw Them Bows" artist="Ludacris"/>

    <song url="PlayList/Planet Rock.mp3" songName="Planet Rock" artist="The Soul Sonic Force" />

    <song url="PlayList/Jam On It.mp3" songName="Jam On It" artist="Newcleus" />

</catalog>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2015 Dec 09, 2015

that's catalog.xml?

if so, what's the problem with that or how do you want to change that?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 09, 2015 Dec 09, 2015

This is what Im trying to do. lets say I have a catalog of 50 songs. (catalog List) now I want to create a playlist for just 10 songs (playlist). Now I want to be able to add new songs from catalog list to playlist and be able to delete songs from the playlist. I also want to be able to add new songs to the catalog list, which will automatically add the songs to the xml database without rewriting the xml playlist. and Thanks again for your time and response.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2015 Dec 09, 2015
LATEST

after parsing catalog.xml in xml_loader_COMPLETE_LOADING(), create an array or new xml for your playlist.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines