0
votes

I am doing Android app using Flash CS6 and Adobe AIR. It is a simple streaming radio player with one button for play and stop. I would like to add a new button with a timer function (sleep) that stops the player or exit the app) after 30 minutes. How could I add this?

Here is the code I am using (works fine):

button_1.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound);
var fl_SC:SoundChannel;
var fl_ToPlay:Boolean = true;
function fl_ClickToPlayStopSound(evt:MouseEvent):void
{
    if(fl_ToPlay)
    {
        var s = new Sound(new URLRequest("http://myradio.com/stream.mp3"));
        fl_SC = s.play();
    }
    else
    {
        fl_SC.stop();
    }
    fl_ToPlay = !fl_ToPlay;
}
2

2 Answers

0
votes
  1. Create another button for this.
  2. Initialize a timer variable default as 0
  3. Add event listeners to your new button for "CLICK" event and "ENTER_FRAME" event both.
  4. Use your timed button's "CLICK" event for setting your timer variable's value to 30 minutes(depends on your framerate) & adding your button "ENTER_FRAME" event listener.
  5. Use your timed button's "ENTER_FRAME" event to countdown your timer variable & check for is it "less than 0" & then run your sleep function & remove event listener "ENTER_FRAME"
  6. I don't want to give you any code, that's not lookin fair for a question easy like that, check for tutorials, you can find lots of ways to solve something like that...
0
votes

I have found a solution. I've linked the button to a new frame with the following code:

var s = new Sound(new URLRequest("http://myradio.com/stream.mp3"));

fl_SC = s.play();

var fl_TimerInstance_2:Timer = new Timer(900000, 1);

fl_TimerInstance_2.addEventListener(TimerEvent.TIMER, fl_TimerHandler_2);

fl_TimerInstance_2.start();

var fl_SecondsElapsed_2:Number = 1;

function fl_TimerHandler_2(event:TimerEvent):void
{
fl_SC.stop();
}

It works perfect.

Thank you very much for your help.

Regards