• Flex 笔记之—音乐控制(SoundChannel, SoundTransform, volume)


    //首先将一个mp3导入了库中,给声音文件设置了music类
    //
    在场景中建立3个按钮buttonplay,Continuebotton,stopbotton
    var musicstar:SoundChannel=new SoundChannel();
    var StopPlayPosition:Number;//停止播放的位置
    var soundLoopPlay:Boolean=true;//是否循环播放
    var soundTF:SoundTransform = new SoundTransform();//控制声音的音量
    var music_play:music = new music();

    soundTF.volume = 0.5;//控制声音的音量现在是原来音量的一半
    musicstar.soundTransform = soundTF;
    stopbotton.visible=true;
    Continuebotton.visible=false;
    function playLoop():void {

    if (soundLoopPlay) {//循环播放
    musicstar = music_play.play();
    musicstar.addEventListener(Event.SOUND_COMPLETE, onSoundPlay);
    } else {
    musicstar = music_play.play();
    }

    }
    function onSoundPlay(evt:Event):void {
    musicstar.stop();//停止播放
    playLoop();
    }

    buttonplay.addEventListener(MouseEvent.CLICK,PLAY_1);

    function PLAY_1(e:MouseEvent):void {
    stopbotton.visible=true;
    Continuebotton.visible=false;
    musicstar.stop();
    playLoop();
    }

    stopbotton.addEventListener(MouseEvent.CLICK,STOP_1);

    function STOP_1(e:MouseEvent):void {
    stopbotton.visible=false;
    Continuebotton.visible=true;
    StopPlayPosition=musicstar.position;
    musicstar.stop();
    }

    Continuebotton.addEventListener(MouseEvent.CLICK,Continue_1);

    function Continue_1(e:MouseEvent):void {
    stopbotton.visible=true;
    Continuebotton.visible=false;
    musicstar=music_play.play(StopPlayPosition);
    musicstar.addEventListener(Event.SOUND_COMPLETE, onSoundPlay);
    }
  • 相关阅读:
    【入门OJ】2003: [Noip模拟题]寻找羔羊
    vue history模式 ios微信分享坑
    JS预解释
    vuex存储和本地存储(localstorage、sessionstorage)的区别
    call、apply、bind
    正则表达式常用元字符
    微信公众号自定义菜单跳转到相关联小程序
    javaScript运动框架之缓冲运动
    javaScript运动框架之匀速运动
    js事件冒泡、阻止事件冒泡以及阻止默认行为
  • 原文地址:https://www.cnblogs.com/liangle/p/2512524.html
Copyright © 2020-2023  润新知