Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Location
    São Paulo, Brasil
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Help! Text in xml mp3 playlist not displaying correctly After randomizing the playing

    Hi!
    I startet to have trouble with the text displaying in the mp3 player after i tried to randomize the song playing in it. The player wont display all of the text in an artist or title.
    Here's an image of the player having trouble displaying thhe text:

    Looking at the artist's field it displays "Usaa aa" when it should display "Susana Baca" Same thing with the title's field, it displays "atao ritos" when it should display "Hatajo de Negritos".

    Here the ActionScript code :

    Code:
    import flash.media.Sound;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    
    // Variables
    var playlist:XML;
    var songlist:XMLList;
    var loader:URLLoader = new URLLoader();
    var imageLoader:Loader = new Loader();
    var currentIndex:Number;
    var currentSound:Sound;
    var numSongs:Number;
    var sc:SoundChannel;
    var autoPlayOption:Boolean = true;
    var totalSoundLength:Number;
    var soundMuted=false;
    var songPlaying:Boolean;
    var pausePoint:Number;
    var volPos:Number;
    
    init();
    
    // Initialize the player
    function init() {
    	loader.addEventListener(Event.COMPLETE, loadPlaylist);
    	loader.load(new URLRequest("playlist.xml"));
    	volumeMc.volumeMask.x=volumeMc.slider.x+5;
    }
    
    // load the playlist
    function loadPlaylist(e:Event): void 
    {
    	playlist=new XML(e.target.data);
    	playlist.ignoreWhite=true;
    	songlist=playlist.song;
    	numSongs=songlist.length();
    	
    	// Check if the player has to start playing
    	if(playlist.@autoplay == "false"){
    		autoPlayOption = false;
    		songPlaying = false;
    	}
    	
    	// randomize the playing 
    	 var k = Math.floor(Math.random()*songlist.length());
    	trace(k);
    	trace(songlist.length());
    	trace(playlist);
    	
    	// Load the first song 
    	var musicReq:URLRequest;
    	var music:Sound = new Sound();
    	
    	musicReq=new URLRequest(songlist[k].url);
    	music.load(musicReq);
    	currentSound=music;
    	stage.addEventListener(Event.ENTER_FRAME, progressBarEvent);
    	music.addEventListener(IOErrorEvent.IO_ERROR, fn_error_handler);
    	currentIndex = k;
    	// Autoplay the first song if its enabled
    	if (autoPlayOption==true) {
    		sc=music.play();
    		songPlaying = true;
    		sc.addEventListener(Event.SOUND_COMPLETE, nextSongAutoPlay);
    		
    	}else{
    		pausePoint = 0;
    	}
    	
    	setText();
    	
    }
    
    // Button controls
    function nextSongClick(e:MouseEvent) {
    	if (e.currentTarget==prevBtn) {
    		if (currentIndex==0) {
    			currentIndex = (numSongs - 1);
    		} else {
    			currentIndex-=1;
    		}
    	}
    	if (e.currentTarget==nextBtn) {
    		if ((currentIndex + 1) == numSongs) {
    			currentIndex=0;
    
    		} else {
    			currentIndex+=1;
    		}
    	}
    	var nextReq:URLRequest=new URLRequest(songlist[currentIndex].url);
    	var nextTitle:Sound=new Sound(nextReq);
    	nextTitle.addEventListener(IOErrorEvent.IO_ERROR, fn_error_handler);
    	if(songPlaying){
    		sc.stop();
    		sc=nextTitle.play();
    		songPlaying = true;
    		sc.addEventListener(Event.SOUND_COMPLETE, nextSongAutoPlay);
    		if(soundMuted == true){
    			sc.soundTransform=new SoundTransform(0);
    		}
    	}else{
    		pausePoint = 0;
    	}
    	currentSound=nextTitle;
    	setText();
    }
    
    // Auto play the next song when the last one has finished playing
    function nextSongAutoPlay(e:Event) {
    	if ((currentIndex + 1) == numSongs) {
    		currentIndex=0;
    	} else {
    		currentIndex+=1;
    	}
    	var nextReq:URLRequest=new URLRequest(songlist[currentIndex].url);
    	var nextTitle:Sound=new Sound(nextReq);
    	sc.stop();
    	nextTitle.addEventListener(IOErrorEvent.IO_ERROR, fn_error_handler);
    	sc=nextTitle.play();
    	if(soundMuted == true){
    		sc.soundTransform=new SoundTransform(0);
    	}
    	songPlaying = true;
    	currentSound=nextTitle;
    	setText();
    	sc.addEventListener(Event.SOUND_COMPLETE, nextSongAutoPlay);
    }
    
    // Set the title/artist text and load the cover
    function setText() {
    	title_txt.text=songlist[currentIndex].title;
    	artist_txt.text=songlist[currentIndex].artist;
    	trace(songlist[currentIndex].title);
    	if(songPlaying == true && soundMuted == false){
    		sc.soundTransform=new SoundTransform(volumeMc.slider.x / 48);
    	}
    	while (cover.container.numChildren) {
    		cover.container.removeChildAt(0);
    	}
    	imageLoader.load(new URLRequest(songlist[currentIndex].cover));
    	imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, showCover);
    }
    
    // Show the cover once it has finished loading
    function showCover(e:Event) {
    	cover.container.addChild(imageLoader.content);
    	var coverTween:Tween=new Tween(cover.container,"alpha",Strong.easeOut,0,1,0.5,true);
    }
    
    // This function keeps track of the progress of the song
    function progressBarEvent(e:Event ) {
    	
    	// Calculate the total length of the current mp3
    	totalSoundLength = (currentSound.bytesTotal / (currentSound.bytesLoaded / currentSound.length));
    	var Milliseconds:Number=totalSoundLength;
    	var Minutes:uint=Math.floor(Milliseconds/60000);
    	var Seconds:uint = (Milliseconds%60000);
    	var SecondsTens:uint=Math.floor(Seconds/10000);
    
    	Seconds=Math.ceil(Seconds%10000);
    	Seconds/=1000;
    
    	totalLength.text=Minutes+":"+SecondsTens+""+Seconds;
    	
    	// Show how much data the song has loaded
    	preLoader.preLoaderMask.x = (100 / totalSoundLength) * currentSound.length;
    	
    	// Progressbar
    	if(songPlaying){
    		var Milliseconds2:Number=sc.position;
    		var Minutes2:uint=Math.floor(Milliseconds2/60000);
    		var Seconds2:uint = (Milliseconds2%60000);
    		var SecondsTens2:uint=Math.floor(Seconds2/10000);
    	
    		Seconds2=Math.ceil(Seconds2%10000);
    		Seconds2/=1000;
    	
    		positionText.text=Minutes2+":"+SecondsTens2+""+Seconds2;
    		preLoader.progressBarSlider.x = ((100 / totalSoundLength) * sc.position) -5;
    	}
    	
    	if (songPlaying) {
    		playBtn.gotoAndStop(1);
    	} else {
    		playBtn.gotoAndStop(2);
    	}
    	if (soundMuted==true) {
    		geluidIcon.gotoAndStop(2);
    	} else {
    		geluidIcon.gotoAndStop(1);
    	}
    }
    
    // Pause / Play  control buttons
    function pausePlayer(e:MouseEvent) {
    	if (songPlaying==true) {
    		pausePoint=sc.position;
    		songPlaying=false;
    		sc.stop();
    	} else if (songPlaying == false) {
    		sc=currentSound.play(pausePoint);
    		currentSound.addEventListener(IOErrorEvent.IO_ERROR, fn_error_handler);
    		if(soundMuted == false){
    			sc.soundTransform=new SoundTransform(volumeMc.slider.x / 48);
    		}else{
    			sc.soundTransform=new SoundTransform(0);
    		}
    		sc.addEventListener(Event.SOUND_COMPLETE, nextSongAutoPlay);
    		songPlaying=true;
    	}
    }
    
    // Hover states of the buttons
    function btnHover(e:MouseEvent) {
    	var hoverTween:Tween=new Tween(e.currentTarget.hover,"alpha",Regular.easeIn,e.currentTarget.hover.alpha,1,0.5,true);
    }
    function btnHoverOut(e:MouseEvent) {
    	var hoverTween:Tween=new Tween(e.currentTarget.hover,"alpha",Regular.easeOut,e.currentTarget.hover.alpha,0,0.5,true);
    }
    
    // Error catching
    function fn_error_handler(e:Event) {
    
    }
    
    // Starts playing the song on the position that the user click ons the progressbar
    function clickProgressBar(e:MouseEvent) {
    	if(songPlaying){
    		sc.removeEventListener(Event.SOUND_COMPLETE, nextSongAutoPlay);
    		preLoader.progressBarSlider.removeEventListener(Event.ENTER_FRAME, progressBarEvent);
    		preLoader.progressBarSlider.x=preLoader.mouseX;
    		sc.stop();
    		songPlaying = true;
    		sc=currentSound.play((totalSoundLength/ 100) * preLoader.progressBarSlider.x );
    		currentSound.addEventListener(IOErrorEvent.IO_ERROR, fn_error_handler);
    		sc.soundTransform=new SoundTransform(volumeMc.slider.x/48);
    		sc.addEventListener(Event.SOUND_COMPLETE, nextSongAutoPlay);
    		preLoader.progressBarSlider.addEventListener(Event.ENTER_FRAME, progressBarEvent);
    	}
    }
    
    // Set the volume
    function clickVolume(e:MouseEvent) {
    	if (soundMuted==true) {
    		soundMuted=false;
    		geluidIcon.gotoAndStop(1);
    	}
    	if (volumeMc.mouseX<=0) {
    		geluidIcon.gotoAndStop(2);
    		soundMuted=true;
    	}
    	if (volumeMc.x<=0&&soundMuted==true) {
    	} else {
    		var volumeTween:Tween = new Tween(volumeMc.slider, "x", Regular.easeOut, volumeMc.slider.x, (volumeMc.mouseX - 7), 0.5, true);
    		var volumeMaskTween:Tween=new Tween(volumeMc.volumeMask,"x",Regular.easeOut,volumeMc.volumeMask.x,volumeMc.mouseX,0.5,true);
    		var volx:Number=volumeMc.mouseX/48;
    		var sp:SoundTransform=new SoundTransform(volx);
    		if (sc!=null) {
    			sc.soundTransform=sp;
    		}
    	}
    }
    
    // Mute the sound
    function muteSound(e:MouseEvent) {
    	if (soundMuted==false) {
    		if(sc!=null){
    			sc.soundTransform=new SoundTransform(0);
    		}
    		var volumeTween:Tween = new Tween(volumeMc.slider, "x", Regular.easeOut, volumeMc.slider.x, -2, 0.5, true);
    		var volumeMaskTween:Tween=new Tween(volumeMc.volumeMask,"x",Regular.easeOut,volumeMc.volumeMask.x,0,0.5,true);
    		volPos=volumeMc.slider.x;
    		soundMuted=true;
    		geluidIcon.gotoAndStop(2);
    	} else {
    		if(sc!=null){
    			sc.soundTransform=new SoundTransform(volPos / 48);
    		}
    		soundMuted=false;
    		var volumeTween2:Tween = new Tween(volumeMc.slider, "x", Regular.easeOut, volumeMc.slider.x, volPos, 0.5, true);
    		var volumeMaskTween2:Tween=new Tween(volumeMc.volumeMask,"x",Regular.easeOut,volumeMc.volumeMask.x, (volPos +5),0.5,true);
    		geluidIcon.gotoAndStop(1);
    	}
    }
    
    // Eventlisteners
    playBtn.addEventListener(MouseEvent.CLICK, pausePlayer);
    nextBtn.addEventListener(MouseEvent.CLICK, nextSongClick);
    prevBtn.addEventListener(MouseEvent.CLICK, nextSongClick);
    
    playBtn.addEventListener(MouseEvent.MOUSE_OVER, btnHover);
    playBtn.addEventListener(MouseEvent.MOUSE_OUT, btnHoverOut);
    
    nextBtn.addEventListener(MouseEvent.MOUSE_OVER, btnHover);
    nextBtn.addEventListener(MouseEvent.MOUSE_OUT, btnHoverOut);
    
    prevBtn.addEventListener(MouseEvent.MOUSE_OVER, btnHover);
    prevBtn.addEventListener(MouseEvent.MOUSE_OUT, btnHoverOut);
    
    preLoader.addEventListener(MouseEvent.CLICK, clickProgressBar);
    volumeMc.addEventListener(MouseEvent.CLICK, clickVolume);
    geluidIcon.addEventListener(MouseEvent.CLICK, muteSound);
    
    // ButtonMode's
    geluidIcon.buttonMode = true;
    playBtn.buttonMode=true;
    nextBtn.buttonMode=true;
    prevBtn.buttonMode=true;
    preLoader.buttonMode=true;
    volumeMc.buttonMode=true;
    volumeMc.slider.buttonMode=true;
    thanks in advanced!
    Last edited by WA; 10-12-2011 at 04:41 PM.

  • #2
    New to the CF scene
    Join Date
    Oct 2011
    Location
    São Paulo, Brasil
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry Guys!
    I myself descovered what was wrong.
    If you come across a similar problem

    you should probably check if you have embeded the font for dinamic text in the swf file.
    here's the tutorial on how to do it.

    Thanks anyway!

  • #3
    New Coder
    Join Date
    Oct 2011
    Location
    New york
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Lightbulb

    Hey there,

    Well the code you've included recreates the XML and recreates the function but it still doesn't load it........

    You've already created the XML and you have the function to reload it, so use it.

    Just a call to the function:
    reload(file, theXml)

    with the filename and the name of the XML in there and that should do you.

    Regards,
    Jackie


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •