3 Replies Latest reply on Jul 22, 2008 2:46 AM by Matt Gifford

    my music player and datagrid xml

    Matt Gifford Level 1
      Hi guys

      I'm playing around with creating an mp3 player using a datagrid drawing from xml.
      I have the grid populated, but the problem is only one song is loading up.

      I cant see a problem with the code, as the correct filename is being selected, but only one of them is playing.
      Have I got the correct code for the URLRequest function to load the song file?
      Should I have some kind of buffering in there?

      My code is below.

      Many thanks for looking, and I hope someone can help.
      Thank you
        • 1. Re: my music player and datagrid xml
          Gregory Lafrance Level 6
          Preferrable to have simplified complete app code with data.
          • 2. Re: my music player and datagrid xml
            Matt Gifford Level 1
            Thanks for the reply, Greg.

            My complete code is below:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="700" height="400" layout="absolute" applicationComplete="init();">

            import mx.collections.XMLListCollection;

            import flash.media.*;
            import mx.controls.Alert;
            import flash.net.URLRequest;

            private var playList:XML;

            private var urlReq:URLRequest;
            private var loader:URLLoader;
            private var sound:Sound;

            private var songArray:Array;

            // Sound Channel to monitor
            private var song:SoundChannel;

            // Sound... Factory for initializing our song.
            private var soundFactory:Sound;

            private var playing:Boolean = false;
            private var stopped:Boolean = true;

            private var fileToPlay:String;
            private var currentItem:String;

            private function init():void {

            private function loadXML():void {
            var urlReq:URLRequest = new URLRequest('playlist.xml');
            var loader:URLLoader = new URLLoader(urlReq);
            loader.addEventListener("complete", xmlLoaded);

            function xmlLoaded(e:Event):void {
            playList = XML(loader.data);

            for each (var obj:Object in playList.item)
            var thisArtist:String = obj.artist.toString();
            var thisTrack:String = obj.track.toString();
            var thisAlbum:String = obj.album.toString();
            var thisFile:String = obj.file.toString();

            songArray.push( thisFile );




            private function playTheSound(file:String):void {
            var urlReq:URLRequest = new URLRequest(file);

            private function loadTune():void {

            if (playing) {
            action_btn.label = '>';
            playing = false;
            nowPlaying.text = '';

            // reset current item variables
            currentItem = '';
            fileToPlay = '';
            } else {

            fileToPlay = tuneDG.selectedItem.file;
            currentItem = tuneDG.selectedIndex.toString();

            // fetch the mp3 file to play
            var urlReq:URLRequest = new URLRequest(fileToPlay);
            soundFactory = new Sound();
            song = soundFactory.play();

            // set the label for the nowplaying text
            nowPlaying.text = 'Now playing: ' + tuneDG.selectedItem.artist + ' - ' + tuneDG.selectedItem.track;

            action_btn.label = '||';
            playing = true;

            private function skipForward():void {


            <mx:DataGrid id="tuneDG" dataProvider="{playList.item}" width="569" doubleClick="loadTune();" doubleClickEnabled="true" height="88" x="121" y="82">
            <mx:DataGridColumn id="artistCol" dataField="artist" headerText="Artist" />
            <mx:DataGridColumn id="trackCol" dataField="track" headerText="Track" />
            <mx:DataGridColumn id="albumCol" dataField="album" headerText="Album" />

            <mx:Button id="action_btn" click="loadTune();" label=">" x="121" y="34"/>
            <mx:HRule x="121" y="64" width="569"/>
            <mx:Label x="169" y="36" width="521" id="nowPlaying"/>
            <mx:Button x="121" y="204" label="&gt;&gt;" id="forward_btn" click="skipForward();" />

            • 3. Re: my music player and datagrid xml
              Matt Gifford Level 1
              Hi guys.

              Can anyone help me with this?

              Many thanks,