A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: MP3 player minor problems pls help!!

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    14

    MP3 player minor problems pls help!!

    I have created an mp3 player following a tutorial, i have the modified the script for the playlist to appear within a scrollPane.
    Unfortunately I have encountered 2 problems i'm not able to fix (im not an AS expert)
    1: The playlist buttons once placed inside the scrollpane odnt work anymore. (they are clikable but the songs dont start when u click on them)
    2: The mp3 player is placed in a section of my site, when i enter that section the player works fine but when i exit that section the music keeps on playing in the background, and in re-enter that section a new track starts ontop of the old one.
    Anyone can help? i have posted on many forums with no answers yet.

    Playlist buttons script:
    Code:
    var mcMain:MovieClip;
    function init() {
    	//empty movie clip in library with linkage name "scrollMovieClip"
    	scrollPane.contentPath = "scrollMovieClip";
    	mcMain = scrollPane.content;
    	trace(mcMain);
    }
    init();
    
    playlist = new XML();
    playlist.ignoreWhite = true;
    playlist.onLoad = function(success) {
    	if (success) {
    		_global.songname = [];
    		_global.songband = [];
    		_global.songfile = [];
    		for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
    		_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
    		_global.songband[i] = playlist.firstChild.childNodes[i].attributes.band;
    		_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
    		mcMain.attachMovie("butTemp", "but"+i, mcMain.getNextHighestDepth(), {_y:16*i+5, _x:5});
    		eval("but"+i).id=i;
    		mcMain["but"+i].but_txt.text = songname[i];
    		scrollPane.invalidate();
    				}
    				
    		mcMain["but"+i].onRelease = function(){
    			clearInterval(timeInterval);
    			_root.timeDisplay_txt.text = "00:00/00:00";
    			_root.sound_mc.songStarter(songfile[this.id]);
    			scrollPane.invalidate();
    		}
    	
    	}
    here is the full mp3 player script:
    Code:
    stop();
    title_txt.autoSize = "left";
    timeDisplay_txt.autoSize = "left";
    toolTip._visible = false;
    var amountLoaded:Number;
    var duration:Number;
    var mcMain:MovieClip;
    function init() {
    	//empty movie clip in library with linkage name "scrollMovieClip"
    	scrollPane.contentPath = "scrollMovieClip";
    	mcMain = scrollPane.content;
    	trace(mcMain);
    }
    init();
    
    playlist = new XML();
    playlist.ignoreWhite = true;
    playlist.onLoad = function(success) {
    	if (success) {
    		_global.songname = [];
    		_global.songband = [];
    		_global.songfile = [];
    		for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
    		_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
    		_global.songband[i] = playlist.firstChild.childNodes[i].attributes.band;
    		_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
    		mcMain.attachMovie("butTemp", "but"+i, mcMain.getNextHighestDepth(), {_y:16*i+5, _x:5});
    		eval("but"+i).id=i;
    		mcMain["but"+i].but_txt.text = songname[i];
    		scrollPane.invalidate();
    				}
    				
    		mcMain["but"+i].onRelease = function(){
    			clearInterval(timeInterval);
    			_root.timeDisplay_txt.text = "00:00/00:00";
    			_root.sound_mc.songStarter(songfile[this.id]);
    			scrollPane.invalidate();
    		}
    	
    	}
    	_root.createEmptyMovieClip("sound_mc", 1);
    	_global.song_nr = random(songfile.length);
    	_root.sound_mc.songStarter(songfile[song_nr]);
    };
    
    function timer(sound_obj) {
    	time = sound_obj.position/1000;
    	min = Math.floor(time/60);
    	min = (min<10) ? "0"+min : min;
    	sec = Math.floor(time%60);
    	sec = (sec<10) ? "0"+sec : sec;
    	timeDisplay_txt.text = min+":"+sec+"/"+totalDuration;
    }
    function duration (){
    	timed = _root.sound_mc.sound_obj.duration/1000;
    	mind = Math.floor(timed/60);
    	mind = (mind<10) ? "0"+mind : mind;
    	secd = Math.floor(timed%60);
    	secd = (secd<10) ? "0"+secd : secd;
    	totalDuration = mind+":"+secd;
    }
    MovieClip.prototype.songStarter = function(file) {
    	if (this.sound_obj) {
    		this.sound_obj.stop();
    		delete this.sound_obj;
    	}
    	this.sound_obj = new Sound(this);
    	this.sound_obj.loadSound(file, true);
    	this.sound_obj.setVolume(0);
    	this.onEnterFrame = function() {
    		if (this.sound_obj.position>0) {
    			delete this.onEnterFrame;
    			timeInterval = setInterval(timer, 1000, this.sound_obj);
    			track = this.sound_obj.id3.songname;
    			artist = this.sound_obj.id3.artist;
    			this._parent.title_txt.text =artist+" - "+track;
    		} else {
    			this._parent.title_txt.text = "loading...";
    		}
    
    	};			
    	this.sound_obj.onSoundComplete = function() {
    		clearInterval(timeInterval);
    		_root.timeDisplay_txt.text = "00:00/00:00";
    		(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
    		_root.sound_mc.songStarter(songfile[song_nr]);
    	};
    	this._parent.volume1.dragger.onPress = function() {
    		startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
    		_root.toolTip._visible = true;
    		setInterval(draggableTip,100);
    		function draggableTip(){
    			_root.toolTip._x = _root._xmouse;
    		}
    		this.onEnterFrame = function() {
    			var p = (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() {
    		_root.toolTip._visible = false;
    		stopDrag();
    		
    	};
    };
    
    function soundStatus(){
    	var amountLoaded = _root.sound_mc.sound_obj.getBytesLoaded() / _root.sound_mc.sound_obj.getBytesTotal();
    	_root.loader.loadBar._width = amountLoaded * 260;
    	duration = _root.sound_mc.sound_obj.duration;
    	position = _root.sound_mc.sound_obj.position;
    	_root.playHead._x = position / duration * 272 + 5;
    }
    
    btn_play.onRelease = function() {
    	clearInterval(timeInterval);
    	_root.timeDisplay_txt.text = "00:00/00:00";
    	this._parent.sound_mc.songStarter(songfile[song_nr]);
    };
    btn_stop.onRelease = function() {
    	clearInterval(timeInterval);
    	_root.timeDisplay_txt.text = "00:00/00:00";
    	this._parent.sound_mc.sound_obj.stop();
    };
    btn_fw.onRelease = function() {
    	clearInterval(timeInterval);
    	_root.timeDisplay_txt.text = "00:00/00:00";
    	(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
    	_root.sound_mc.songStarter(songfile[song_nr]);
    };
    btn_rev.onRelease = function() {
    	clearInterval(timeInterval);
    	_root.timeDisplay_txt.text = "00:00/00:00";
    	(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
    	_root.sound_mc.songStarter(songfile[song_nr]);
    };
    playlist.load("playlist.xml");
    setInterval(duration,100);
    setInterval(soundStatus,100);
    I hope i will find some solutions here
    Thanks in advance

  2. #2
    Junior Member
    Join Date
    Jun 2009
    Posts
    14
    bumpppp!!!!!

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