A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [CS3] Mp3 player problems

  1. #1
    Junior Member
    Join Date
    Jul 2008
    Posts
    9

    [CS3] Mp3 player problems

    Hi all,
    I followed these tutorials http://www.**********.com/publish/tu..._xml_part_iii/ to create an mp3 player. I've basically finshed I just have 3 questions.

    1. I'd like to make my playlist songs have a background so that when I hover over one of the songs in the playlist the background is revealved. Like this mp3 player: http://flashden.net/files/11475/index.html It would also be great for the background of the song that's playing be highlighted as well, just like in that example above.

    2. How can I get the playHead to work as a button so that I can scrub through the amount that has loaded of the song to start playing from somewhere else. In that example from flashden you can see how the playHead is able to be moved and you can start the song from somewhere else...

    3. Also there is a problem with my playlist. If I click on a song in the playlist it will play that song...but at the end it replays the song instead of going to the next song in the playlist...how can I fix this.

    I can put up my actionscript if you'd like to see it...

    Thanks for any help,
    Matt

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Hi and welcome to Flashkit. Apparently the tutorial's url is one that got banned from these boards (thus the ***) You will therefore need to provide some code and a mock-up fla, to get help with your issues. Please read this forum guidelines (link in my footer) where you find info on how to post code in your threads.

    gparis

  3. #3
    Junior Member
    Join Date
    Jul 2008
    Posts
    9
    Hey thanks, no problem...don't know what you mean by mock fla but here's my code for anyone who can help me out.

    Thanks,
    Matt

    PHP Code:
    stop();
    playlist = new XML();
    playlist.ignoreWhite true;
    playlist.onLoad = function(success) {
        if (
    success) {
            
    _global.songname = [];
            
    _global.songalbum = [];
            
    _global.songfile = [];
            
    _global.songlength = [];
            for (var 
    0i<playlist.firstChild.childNodes.lengthi++) {
                
    _global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
                
    _global.songalbum[i] = playlist.firstChild.childNodes[i].attributes.album;
                
    _global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
                
    _global.songlength[i] = playlist.firstChild.childNodes[i].attributes.length;
                
    // trace(songname[i]+"  "+songfile[i]+" "+songalbum[i]);
            
    attachMovie("butTemp","but"+i,i+50);
            eval(
    "but"+i).id=i;
            
    _root["but"+i]._x 25;
            
    _root["but"+i]._y 100 + (i*37);
            
    _root["but"+i].but_txt1.text songname[i];
            
    _root["but"+i].but_txt2.text songalbum[i];
            
    _root["but"+i].but_txt3.text songlength[i];

            
    _root["but"+i].onRelease = function(){
                
    clearInterval(timeInterval);
                
    _root.timeDisplay_txt.text "0:00";
                
    _root.sound_mc.songStarter(songfile[this.id], songname[this.id]);
            }
        }
    }
        
    _root.createEmptyMovieClip("sound_mc"1);
        
    _global.song_nr 0;
        
    _root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songalbum[song_nr]);
    };
    function 
    timer(sound_obj) {
        
    time sound_obj.position/1000;
        
    min Math.floor(time/60);
        
    min = (min<10) ? ""+min min;
        
    sec Math.floor(time%60);
        
    sec = (sec<10) ? "0"+sec sec;
        
    timeDisplay_txt.text min+":"+sec;
    }
    MovieClip.prototype.songStarter = function(filenamealbum) {
        if (
    this.sound_obj) {
            
    this.sound_obj.stop();
            
    delete this.sound_obj;
        }
        
    this.sound_obj = new Sound(this);
        
    this.sound_obj.loadSound(filetrue);
        
    this.onEnterFrame = function() {
            if (
    this.sound_obj.position>0) {
                
    delete this.onEnterFrame;
                
    this._parent.display_txt.text name;
                
    timeInterval setInterval(timer1000this.sound_obj);
            } else {
                
    this._parent.display_txt.text "loading...";
            }
        };
        
    this.sound_obj.onSoundComplete = function() {
            
    clearInterval(timeInterval);
            
    this._parent.timeDisplay_txt.text "0:00";
            (
    song_nr == songfile.length-1) ? _global.song_nr=_global.song_nr++;
            
    _root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songalbum[song_nr]);
        };
        
    this._parent.volume1.dragger.onPress = function() {
            
    startDrag(thistrue0this._ythis._parent.volBG._widththis._y);
            
    this.onEnterFrame = function() {
                var 
    = (this._x/this._parent.volBG._width)*100;
                
    this._parent._parent.sound_mc.sound_obj.setVolume(p);
            };
        };
        
    this._parent.volume1.dragger.onRelease = function() {
            
    delete this.onEnterFrame;
            
    stopDrag();
        };
        
    this._parent.volume1.dragger.onReleaseOutside = function() {
            
    stopDrag();
        };
    };

    setInterval(soundStatus,1);

    function 
    soundStatus(){
        var 
    amountLoaded _root.sound_mc.sound_obj.getBytesLoaded() / _root.sound_mc.sound_obj.getBytesTotal();
        
    _root.loader.loadBar._width amountLoaded 311;
        
    duration = (_root.sound_mc.sound_obj.getBytesTotal() * _root.sound_mc.sound_obj.duration) / _root.sound_mc.sound_obj.getBytesLoaded();
        
    position _root.sound_mc.sound_obj.position;
        
    _root.playHead._x position duration 297 21;
    }

    btn_play.onRelease = function() {
        if (
    pause == true){ // no comment....
            
    this._parent.sound_mc.sound_obj.start(posiP); // start sound from the previously saved position
        
    }
        else if (
    stop == true){
            
    this._parent.sound_mc.sound_obj.start(0);
        }
        else {
            
    clearInterval(timeInterval);
            
    this._parent.timeDisplay_txt.text "0:00";
            
    this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songalbum[song_nr]);
        }
    };
    btn_pause.onRelease = function() { //pause button function
        
    this._parent.sound_mc.sound_obj.stop(); //stop the current sound
        
    posiP _root.sound_mc.sound_obj.position 1000// save the current position in a new variable and divide by 1000 (ms -> sec)
        
    pause true;//set the variable pause to true
        
    stop false;
    }
    btn_stop.onRelease = function() {
        
    this._parent.sound_mc.sound_obj.start(0);
        
    this._parent.sound_mc.sound_obj.stop();
        
    pause false;
        
    stop true;
    };

    playlist.load("playlist.xml"); 

  4. #4
    Junior Member
    Join Date
    Jul 2008
    Posts
    9
    I was actually able to figure out how to make the background of each playlist entry highlight when you hovered over them by adding these lines of code underneath the _root["but"+i].onRelease function near the top of the code.
    PHP Code:
    _root["but"+i].song_bg._alpha 0;
            
    _root["but"+i].onRollOver = function() {
                
    this.song_bg._alpha 65;
            }
            
    _root["but"+i].onRollOut = function() {
                
    this.song_bg._alpha 0;
            } 
    Still can't figure out how to make the song that is playing be constantly highlighted though...


    I also wanted to make my #3 point clearer from the first post. If I let the songs play by themselves without touching the playlist at all, each song will play successively (ie. song1 plays, then song2, then song3, etc.). The only problems occur when I physically click on another song in the playlist, that's when songs get repeated (ie. i start song1 but don't wait for it to finish. I click on song2 and then listen to the entire song. the next song that plays is song2 again...) It seems as though when I click on a song, the onSoundComplete function doesn't register that the song I clicked on should now be 0 in the array and the song after it should be the next one in the playlist...

    I tried adding
    PHP Code:
    song_nr == songfile.length-1) ? _global.song_nr=_global.song_nr++; 
    to the _root["but"+i].onRelease function near the top. This ended up working until I clicked on the same song that was playing (ie. song1 starts playing but I don't wait for it to finish, I click song1 in the playlist and then let the entire song play out, the next song will be song1 again)...


    Again, thanks in advance for any direction/help anyone can give me.

    Matt
    Last edited by mlmorg; 07-06-2008 at 02:24 AM.

  5. #5
    Junior Member
    Join Date
    Jul 2008
    Posts
    9
    Back again.

    Been trying to figure out how to scrub the playHead through the loader and start the music from that new position. I wrote this code:

    PHP Code:
    _root.loader.playHead.onPress = function() {
        
    this._parent._parent.sound_mc.sound_obj.stop();
        
    this.startDrag(false0, -1311, -1);
    }

    _root.loader.playHead.onRelease _root.loader.playHead.onReleaseOutside = function() {
        
    this.stopDrag();
        
    xmouse _root.loader.playHead._x;
        
    this._parent._parent.sound_mc.sound_obj.start(((duration xmouse) / _root.loader.loadBar._width) / 1000);

    Unfortunately, I'm not able to drag the playHead at all with this code...don't know why.

    I even changed it to this.startDrag() with no constraints and I'm then only able to move the playHead vertically not horizontally...why is it not letting me move the playHead horizontally??

    Thanks,

    Matt

  6. #6
    Junior Member
    Join Date
    Jul 2008
    Posts
    9
    Ok back again and have fixed a lot of my problems...

    I was able to get the playHead to scrub by adding a clearInterval because the Interval above it had been keeping it in place.

    I was also able to highlight the playing song in the playlist by adding this line where needed:
    PHP Code:
    _root["but"+song_nr].song_bg._alpha 20


    So I was able to fix a lot but I still have some more questions:

    1. ** figured this out **

    2. Is it possible to scrub the timeDisplay while I scrub through the track with the playHead? (ie. if I want to go to another part in the song and I use the playHead to scrub/drag through the song, can I get the timeDisplay to display the time/s at which I'm scrubbing through?)

    3. Lastly, it would be nice to have a scrollbar on the playlist items so that when there's a lot of them you can scroll down to see the rest. Since the actionscript pulls the movieclip into the frame and then adds multiple depending on how many songs are in the array, I don't really know how to create a scrollbar movie clip to house these...it'd be great if someone could shed some light on how to do this.


    Hopefully someone can help me with these last few questions.

    Thanks,
    Matt
    Last edited by mlmorg; 07-07-2008 at 07:29 PM.

  7. #7
    Junior Member
    Join Date
    Jul 2008
    Posts
    9
    haha i think this is the funniest thread ever


    OK so I've figured everything out now except:

    I want to make a scrollbar to scroll through my playlist items. They are loaded into the movie using actionscript:

    PHP Code:
    attachMovie("butTemp","but"+i,i+50);
            eval(
    "but"+i).id=i;
            
    _root["but"+i]._x 20;
            
    _root["but"+i]._y 99 + (i*47);
            
    _root["but"+i].but_txt1.text songname[i];
            
    _root["but"+i].but_txt2.text songalbum[i];
            
    _root["but"+i].but_txt3.text songlength[i];
            
    loadMovie(songcover[i], _root["but"+i].picLoader2); 
    How can I add a scrollpane around these playlist items so that if, once they are all loaded from the array, their total length is larger than the scrollpane area.

    I'd really love it if someone helped me out with this one...PLEASE! ha...even though I'll probably be back in a day or two saying I figured it out myself hahaha

    Thanks!

    Matt

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