A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] Mp3 won't work!!

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    10

    resolved [RESOLVED] Mp3 won't work!!

    Hi,

    I have created an mp3 player with the code found below, it works fine in flash, as a .swf and if I load the html page into a browser it plays fine, however when I add it to my website which I am testing on my local machine(mac osx) it will only play very small mp3 files, I've tried increasing the buffer in the actionscript, getting rid of any id3 tags and re-encoding the mp3s with soundbooth and using a number of different tracks from different sources but for some reason it will not work! Does anyone know why???

    here's my code:
    Code:
    var soundReq:URLRequest = new URLRequest("new_file.mp3");
    var sound:Sound = new Sound;
    var  soundControl:SoundChannel = new SoundChannel();
    var volumeControl:SoundTransform = new SoundTransform();
    var resumeTime:Number = 0;
    var context:SoundLoaderContext = new SoundLoaderContext(1000, false);
    
    sound.load(soundReq, context);
    sound.addEventListener(Event.ACTIVATE, onComplete);
    
    volume_mc.slider_mc.buttonMode = true;
    
    function onComplete(event:Event):void
    {
    	play_btn.addEventListener(MouseEvent.CLICK, playSound);
    	stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
    	volUp_btn.addEventListener(MouseEvent.CLICK, increaseVol);
    	volDown_btn.addEventListener(MouseEvent.CLICK, decreaseVol);
    }
    
    function playSound(event:MouseEvent):void
    {
    	soundControl = sound.play(resumeTime);
    	pause_btn.visible = true;
    	pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
    	play_btn.visible = false;
    	play_btn.removeEventListener(MouseEvent.CLICK, playSound);
    }
    
    function pauseSound(event:MouseEvent):void
    {
    	resumeTime = soundControl.position;
    	soundControl.stop();
    	play_btn.visible = true;
    	play_btn.addEventListener(MouseEvent.CLICK, playSound);
    	pause_btn.visible = false;
    	pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound);
    	if(resumeTime >= 1)
    	{
    		playDown_mc.visible = true;
    		play_btn.alpha = 0;
    	}
    }
    
    function stopSound(event:MouseEvent):void
    {
    	soundControl.stop();
    	play_btn.visible = true;
    	play_btn.addEventListener(MouseEvent.CLICK, playSound);
    	pause_btn.visible = false;
    	pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound);
    	resumeTime = 0;
    	if(playDown_mc.visible = true)
    	{
    		playDown_mc.visible = false;
    		play_btn.alpha = 1;
    	}
    }
    
    function increaseVol(event:MouseEvent):void
    {
    	if(volume_mc.slider_mc.x <= 96)
    	{
    	volume_mc.slider_mc.x += 4;
    	volume_mc.slider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);
    	}
    }
    
    function decreaseVol(event:MouseEvent):void
    {
    	if(volume_mc.slider_mc.x >= 0)
    	{
    	volume_mc.slider_mc.x -= 4;
    	volume_mc.slider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);
    	}
    }
    
    pause_btn.visible = false;
    playDown_mc.visible = false;
    
    //---VOLUME SLIDER---//
    var dragging:Boolean = false;
    var rectangle:Rectangle = new Rectangle(0,0,100,0);
    volume_mc.slider_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragIt);
    stage.addEventListener(MouseEvent.MOUSE_UP, dropIt);
    
    function dragIt(e:Event):void
    {
    	volume_mc.slider_mc.startDrag(false,rectangle);
    	dragging = true;
    	volume_mc.slider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);
    }
    
    function dropIt(e:Event):void
    {
    	if (dragging)
    	{
    		volume_mc.slider_mc.stopDrag();
    		dragging = false;
    	}
    }
    
    function adjustVolume(e:Event):void
    {
    	var vol:Number = volume_mc.slider_mc.x / 100;
    	var st:SoundTransform = new SoundTransform(vol);
    	if (soundControl != null)
    	{
    		soundControl.soundTransform = st;
    	}
    }
    if anyone here can help it might just stop me from pulling my hair out.

    thanks in advance

  2. #2
    Junior Member
    Join Date
    Nov 2009
    Posts
    10
    Oh well,

    its a bit embarrassing but it was the browsers cache!

    Cleared it and all works fine now.

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