Skip to main content
Arioman
Inspiring
March 10, 2013
Question

add repeat sound and More mp3 to this player

  • March 10, 2013
  • 1 reply
  • 641 views

hi , i have simple Start/pause/Stop Mp3 player

here is action script :

//imports the necessary as events

import flash.events.Event

import flash.events.MouseEvent;

import flash.media.Sound;

import flash.media.SoundChannel;

import flash.net.URLRequest;

var isPlaying:Boolean = new Boolean();

var pausePosition:Number = new Number();

//Create an instance of the Sound class

var soundClip:Sound = new Sound();

//Create a new SoundChannel Object

var sndChannel:SoundChannel = new SoundChannel();

//Load sound using URLRequest

soundClip.load(new URLRequest("song.mp3"));

//Create an event listener that wll update once sound has finished loading

soundClip.addEventListener(Event.COMPLETE, onComplete, false, 0, true);

controller.addEventListener(MouseEvent.MOUSE_DOWN, btnPressController, false, 0, true);

stop_btn.addEventListener(MouseEvent.MOUSE_DOWN, btnPressStop, false, 0, true);

function onComplete(evt:Event):void {

    //Play loaded sound

    sndChannel = soundClip.play();

    isPlaying = true;

}

function btnPressController(evt:MouseEvent):void

{

    switch(isPlaying)

    {

        case true:

            controller.gotoAndStop(2);

            pausePosition = sndChannel.position;

            sndChannel.stop();

            isPlaying = false;

        break;

        case false:

            controller.gotoAndStop(1);

            sndChannel = soundClip.play(pausePosition);

            isPlaying = true;

        break;

    }

}

function btnPressStop(evt:MouseEvent):void

{

    pausePosition = 0;

    sndChannel.stop();

    controller.gotoAndStop(2);

    isPlaying = false;

}

but now i need to add Repeat Function to repeat Sound , i add this script :

soundClip.addEventListener(Event.SOUND_COMPLETE,introloop);

function introloop(e:Event):void {

    sndChannel = soundClip.play(0, 9999);

    isPlaying = false

}

but it now work.

any help ??  thanks ...

Also It will be Great if Help me to add more Than One sound ( maybe With Next sound bt )

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
March 10, 2013

Why do you specify isPlaying to be false i the introloop function?

You should put a trace in that function to see if the end of the sound is detected

Arioman
AriomanAuthor
Inspiring
March 11, 2013

thanks

i just use isPlaying = false or True for a little bit Hope and nothing chance ...

where i must Put Trace script and how this script can help me ??

Arioman
AriomanAuthor
Inspiring
March 14, 2013

ok i solved the repeat Problem ...

now anyone can help me about adding more Mp3 tracks and Next button please