A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Personalized mp3 player

  1. #1

    Personalized mp3 player

    Hi

    I recently did the tutorials on www.gotoandlearn.com for customizing the video componets, i am now wishing todo this for mp3 files they need to stream like the video etc. i have tried to amend the code for the video player i have built but it wont work for me unless i have video n there.

    can anyone help me with this problem. cheers Slaup

  2. #2
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    Post the code your using. Custom MP3 player are as easy as.....

    code:

    myPlayer=new Sound();
    myPlayer.loadSound("somefile.mp3",true);


  3. #3
    Code:
    var nc:NetConnection = new NetConnection();
    nc.connect(null);
    
    var ns:NetStream = new NetStream (nc);
    
    ns.setBufferTime(30);
    
    ns.onStatus = function(info) {
    	if(info.code == "NetStream.Buffer.Full") {
    		bufferClip._visible = false;
    	}
    	if(info.code == "NetStream.Buffer.Empty") {
    		bufferClip._visible = true;
    	}
    	if(info.code == "NetStream.Play.Stop") {
    		ns.seek(0);
    	}
    }
    
    theVideo.attachVideo(ns);
    ns.play("flv/admin.flv");
    
    rewindButton.onRelease = function() {
    	ns.seek(0);
    }
    
    playButton.onRelease = function() {
    	ns.pause();
    }
    
    var videoInterval = setInterval(videoStatus,100);
    var amountLoaded:Number;
    var duration:Number;
    
    ns["onMetaData"] = function(obj) {
    	duration = obj.duration;
    }
    
    function videoStatus() {
    	amountLoaded = ns.bytesLoaded / ns.bytesTotal;
    	loader.loadbar._width = amountLoaded * 197;
    	loader.scrub._x = ns.time / duration * 197;
    }
    
    //var scrubInterval;
    
    //loader.scrub.onPress = function() {
    //	clearInterval(videoInterval)
    //	scrubInterval = setInterval(scrubit,10);
    //	this.startDrag(false,.9,this._y,197,this._y);
    //}
    
    //loader.scrub.onRelease = loader.scrub.onReleaseOutside = function() {
    //	clearInterval(scrubInterval);
    //	videoInterval = setInterval(videoStatus,100);
    //	this.stopDrag();
    //}
    
    //function scrubit() {
    //	ns.seek(Math.floor((loader.scrub._x/197)*duration));
    //}
    
    
    var theMenu:ContextMenu = new ContextMenu();
    theMenu.hideBuiltInItems();
    _root.menu = theMenu;
    
    var i1:ContextMenuItem = new ContextMenuItem("::: Video Controls :::",trace);
    theMenu.customItems[0] = i1;
    
    var i2:ContextMenuItem = new ContextMenuItem("Play / Pause Video",pauseIt,true);
    theMenu.customItems[1] = i2;
    
    var i3:ContextMenuItem = new ContextMenuItem("Replay Video",replayIt);
    theMenu.customItems[2] = i3;
    
    var i4:ContextMenuItem = new ContextMenuItem("Copyright 2005",trace,true);
    theMenu.customItems[3] = i4;
    
    
    
    function pauseIt() {
    	ns.pause();
    }
    
    function replayIt() {
    	ns.seek(0);
    }
    
    
    _root.createEmptyMovieClip("vSound",_root.getNextHighestDepth());
    vSound.attachAudio(ns);
    
    var so:Sound = new Sound(vSound);
    
    so.setVolume(100);
    
    mute.onRollOver = function() {
    	if(so.getVolume() == 100) {
    		this.gotoAndStop("onOver");
    	}
    	else {
    		this.gotoAndStop("muteOver");
    	}
    }
    
    mute.onRollOut = function() {
    	if(so.getVolume() == 100) {
    		this.gotoAndStop("on");
    	}
    	else {
    		this.gotoAndStop("mute");
    	}
    }
    
    mute.onRelease = function() {
    	if(so.getVolume() == 100) {
    		so.setVolume(0);
    		this.gotoAndStop("muteOver");
    	}
    	else {
    		so.setVolume(100);
    		this.gotoAndStop("onOver");
    	}
    }
    
    stop();
    this is the code i have used to create my own streaming video player, would your above code stream the mp3>

  4. #4
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    Yes, the code I posted will stream the mp3 file into the sound object. It doesn't account for much of the code you have such as a playhead scrubber, start and stop buttons, etc..., but it is the start of creating your own MP3 player. Check out the Groupy BandMate MP3 player on my site. It is probably a bit more dynamic that what your shooting for, but works very well. Here is a nice tutorial for creating a MP3 player....

    http://www.kennybellew.com/tutorial/

  5. #5
    thanks ill give it alook

  6. #6
    Hi i have read your site site and it does have features i would like to use.. unfortunaly i am unable to use ppal. Basically reading your site i need a player that loads 6 mp3's so you can go next next etc it shows the lenght of the track and the time your on in ttrack a valume slider and somehow show the name of the track that it is playing.. they also need to stream as loading 6 mp3's at once would kill most connections, i know this is alot and im still trying to compile it all from your site but with no luck.. any advice would be great as its gonna take me ages to sort it out from reading your site thats if i can.

    Cheers Me

  7. #7
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    The tutorial is not my website. Actually, I discovered if after I created my MP3 player. I use a few methods differently, but the tutorial is one of the more complete tutorials I've seen for using the sound object. One suggestion would be to go to the movies section here at FK and look for a demo MP3 player to guide you in construction of your own. I know there are several there as I donated one

    Regards
    NTD

  8. #8
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    you can download my free xml driven mp3 player at www.flashmatics.co.uk/blog
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  9. #9

  10. #10
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    hey nice guitaring by jeff beck ..nice tune
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  11. #11
    Cheers buys ill give em a look, i have been busy this weekend but have come unstuck i have created what i need just i now need a loadbar for each track, on the site mentioned above it says how to do one but i can't get it working with my code below anyone got any ideas how i can achieve this??

    Code:
    onClipEvent (load) {
    nextSound = 1;
    }
    // 
    onClipEvent (enterFrame) {
    // Use the following if you want this information to display in dynamic text boxes.
    _root.mySoundDurationText = _root["mySound"+nextSound].duration/1000;
    _root.mySoundPositionText = _root["mySound"+nextSound].position/1000;
    // Set variables for your sounds duration and position. However, for this player, only the position is used.
    mySoundDuration = _root["mySound"+nextSound].duration/1000;
    mySoundPosition = _root["mySound"+nextSound].position/1000;
    if (mySoundPosition == null) {
    mySoundPosition = 0;
    }
    // Text for dynamic song names
    _root.songListMenu.myText1.mySound1Text = "This is the title of Song 1";
    _root.songListMenu.myText2.mySound2Text = "This is the title of Song 2";
    _root.songListMenu.myText3.mySound3Text = "This is the title of Song 3";
    _root.songListMenu.myText4.mySound4Text = "This is the title of Song 4";
    _root.songListMenu.myText5.mySound5Text = "This is the title of Song 5";
    // -------------------BUTTON PRESS
    // -----nextSongButton
    _root.nextSongButton.onPress = function() {
    nextSound++;
    if (nextSound>5) {
    nextSound = 1;
    }
    stopAllSounds();
    mySoundPosition = 0;
    mySoundPaused = 0;
    songName = ["sample"+nextSound+".mp3"];
    _root["mySound"+nextSound].loadSound(songName, true);
    };
    _root.nextSongButton.onRollOver = function() {
    _root.menuText.nextText = "Next Song";
    };
    _root.nextSongButton.onRollOut = function() {
    _root.menuText.nextText = "";
    };
    // 
    // -----prevSongButton
    _root.prevSongButton.onPress = function() {
    nextSound--;
    if (nextSound<1) {
    nextSound = 5;
    }
    stopAllSounds();
    mySoundPaused = 0;
    _root["mySound"+nextSound].start();
    };
    _root.prevSongButton.onRollOver = function() {
    _root.menuText.prevText = "Prev Song";
    };
    _root.prevSongButton.onRollOut = function() {
    _root.menuText.prevText = "";
    };
    // -----playButton
    _root.playButton.onPress = function() {
    stopAllSounds();
    songName = ["sample"+nextSound+".mp3"];
    if (mySoundPaused != 1) {
    _root["mySound"+nextSound].loadSound(songName, true);
    }
    _root["mySound"+nextSound].start(mySoundPosition, 0);
    mySoundPaused = 0;
    };
    // -----stopButton
    _root.stopButton.onPress = function() {
    _root["mySound"+nextSound].stop();
    mySoundPaused = 0;
    };
    // -----pauseButton
    _root.pauseButton.onPress = function() {
    mySoundPaused = 1;
    _root["mySound"+nextSound].stop();
    };
    }
    // END
    it plays 5 songs and loads them dynamically all i need is the progress bar.

    Cheers

  12. #12
    or the one from www.flashmatics.co.uk/blog would be perfect if instead on the scrolling list of songs it was 6 buttons, if anyone has any ideas, sorry flash is not my best subject

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