A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23

Thread: please help me with mp3 player...

  1. #21
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Well, I have fixed the fla for you. Only first 3 songs currently + some code in the prev/next/contract/expand buttons.

    But you should listen to hp3, if you want to do your life easier, you could use only 2 frames and change songs to be loaded through the list in the array or something (I would try that way). Then again, if you are not very comfortable with arrays and changing variables dynamically, you could continue with this.

  2. #22
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    when you are developing an application in Flash, I think it is best to attept to keep all code in frame 1 as much as possible. Spreading code across frames is typical for presentations, but for applications you generally run into problems when the code is all over the place. Mind you, this is a rule of thumb, not a requirement.

    when making a sound application using sound objects, you usually declare the sound object once, then assign new sounds to it through loadSound or attachSound. It is unneccessary and not a good plan to re-create a sound object just to play a sound.

    so in your case create a sound object once in frame 1 (see below) and reuse it.

    you have buttons in the interface to select prev/next tracks
    when you click a button it should:
    determine previous or next track
    load a new mp3,

    You could do all this with 2 functions.

    Think of all of your sound urls and names as a list stored in an array. Prev and Next buttons just move through the array.

    For the expand and contract, you dont need to change frames either. You can show and hide the contracted version using the _visible property.

    Below is the basic concept of your application, but coded within one frame. You may need to modify some target paths depending upon whether your buttons are within mcs or not.

    Code:
    /*
    create 1 mc for contracted player
    create 1 mc for expanded player
    put all code and mcs in frame 1
    */
    
    expandedmc._visible = false; // default to hiding expanded mc
    mp3Player = new Sound();
    
    // list mp3 urls
    mp3URLS = new Array("url1.mp3",url2.mp3","url3.mp3"...);
    
    count; // declare global variable
    
    // load next sound
    function getNext(){
      mp3Player.stop(); // stop current sound
      count = (count <= 0) ? mp3URLS.length - 1 : count - 1;
      mp3Player.loadSound(mp3URLS[count],true); //stream the mp3
    }
    
    // load previous sound
    function getPrev(){
      mp3Player.stop(); // stop current sound
      count = (count == mp3URLS.length - 1) ? count = 0 : count + 1;
      mp3Player.loadSound(mp3URLS[count],true); //stream the mp3
    }
    
    // assign functions to button events
    nextButton.onRelease = getNext;
    prevButton.onRelease = getPrev;
    
    // assign expand/contract interface code to button events
    expandButton.onRelease = function () {expandedmc._visible = true}
    contractButton.onRelease = function() {expandedmc._visible = false}

  3. #23
    Member
    Join Date
    Aug 2003
    Posts
    30
    Guys, I cant thank you both enough for your patience, advice & help with the player. I now understand what your trying to say with the Arrays (yippie!). This will explain my late replys today.

    I signed up for a actionscript course with vtc.com. I went straight to the "Variables and Arrays" section & BANG, right between the eyes!, there it was....now I understand what you guys were trying to tell me all this time. Duh me

    I should of done this ages ago

    I really want to tackle this, cause its lit a light on a few other thngs Ive wanted to do with this method. Give me a day or 2, and I'll show you both the new mp3 player with the new code. You guys are the best!!!!!!.

    cheers!
    Last edited by toodave; 09-19-2003 at 06:21 PM.

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