简体   繁体   中英

flex mobile on android : how to stop music when application is minimized

I have developped a small application in Flex Mobile (Project actionscript mobile in flex4.7). I have a background music.

My problem is that music is still being played when application is minimzed (Home android button): I would like the music to be paused when Home button is being pressed and resumed, when application is active again.

Any clues ?

In your document class, listen for the Stage class's ACTIVATE and DEACTIVATE events:

package
{
    import flash.display.Sprite;
    import flash.events.Event;

    public class Main extends Sprite
    {
        public function Main():void 
        {
            stage.addEventListener(Event.ACTIVATE, onAppActivated);
            stage.addEventListener(Event.DEACTIVATE, onAppDeactivated);
        }

        private function onAppActivated(e:Event):void 
        {
            // Play audio
        }

        private function onAppDeactivated(e:Event):void 
        {
            // Pause audio
        }
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM