目录

麦克风音量感知<Microphone>

功能概述

麦克风音量感知功能根据全局变量microphone_state、microPhone_volume和isSupportMicro实现。

通过调用这些全局变量,实现麦克风音量感知创意主题。

应用场景

通过对手机的麦克风吹气,触发锁屏和桌面上的创意动效。例如:

功能说明

变量说明

变 量

类  型

选 项

注 释

isSupportMicro

数值

必填

开关变量(固定名称):1 开启录音; 0 停止录音。默认为0。

microPhone_volume

数值

必填

麦克风分贝值,实时获取。

microphone_state

数值

选填

麦克风吹气状态:1 短吹 ;2 长吹;0 无状态。默认为0。

制作麦克风音量感知主题时,必须设置变量isSupportMicro,以开启录音开关,示例如下:
<Var name="isSupportMicro" expression="0" persist="false"/
<Image x="100" y="400" w="258" h="258" src="dian.png" />
<Button x="100" y="400" w="258" h="258" >
    <Trigger action="down">
	<VariableCommand name="isSupportMicro" expression="not(#isSupportMicro)" />
    </Trigger>
</Button>

应用示例

示例:在桌面上,对着手机麦克风吹气, 触发风车转动、杆上的飘带飘动和兔子的耳朵摆动。

示例脚本:

<?xml version="1.0" encoding="UTF-8"?>
<CommonWallpaper version="1" screenWidth="1080" frameRate="30" displayDesktop="true">
    <Var persist="true" expression="#screen_width" const="true" name="w"/>
    <Var persist="true" expression="#screen_height" const="true" name="h"/>
    <Var persist="true" expression="(#screen_height-2400)/2" const="true" name="qh"/>
    <Var expression="ifelse(gt(#screen_height,1920),260,120)" name="pos"/>
    <Var expression="max(#w/1080,#h/2400)" name="ratio"/>

    <!--初始化-->
    <ExternalCommands>
         <Trigger action="resume">
              <VariableCommand persist="false" expression="1" name="isSupportMicro"/>
              <Command value="stop" target="gan.animation"/>
              <Command value="stop" target="piaodai.animation"/>
              <Command value="stop" target="changchui.animation"/>
              <Command value="stop" target="tuzi.animation"/>
         </Trigger>
     </ExternalCommands>

     <Image y="#h" x="#w/2" h="#ratio*2400" w="1080*#ratio" alignV="bottom" align="center" src="bg.png" scaleType="fill"/>
     <Var expression="#microPhone_volume" name="changed_volume" threshold="5">
         <Trigger>
              <Command value="play" target="gan.animation" condition="ge(#microPhone_volume, 70)"/>
              <Command value="play" target="piaodai.animation" condition="ge(#microPhone_volume, 70)"/>
              <Command value="play" target="changchui.animation" condition="ge(#microPhone_volume, 70)"/>
              <Command value="play" target="tuzi.animation" condition="ge(#microPhone_volume, 70)"/>
         </Trigger>
     </Var>

     <!--杆-->
     <Image name="gan" y="#h-920" x="698" alignV="bottom" align="center" src="gan/gan_0.png">
         <SourcesAnimation repeat="2">
              <Source src="gan/gan_0.png" time="0"/>
              <Source src="gan/gan_1.png" time="40"/>
              ......
              <Source src="gan/gan_74.png" time="2960"/>
              <Source src="gan/gan_75.png" time="3000"/>
         </SourcesAnimation>
     </Image>

     <!--兔子耳朵-->
     <Image name="tuzi" y="#h-742" x="#w/2" h="#ratio*830" w="1080*#ratio" alignV="bottom" align="center" src="erduo/erduo_0.png">
         <SourcesAnimation repeat="5">
              <Source src="erduo/erduo_0.png" time="0"/>
              <Source src="erduo/erduo_1.png" time="40"/>
              ......
              <Source src="erduo/erduo_23.png" time="920"/>
              <Source src="erduo/erduo_24.png" time="960"/>
         </SourcesAnimation>
     </Image>

     <!--风车-->
     <Var name="changchui">
         <VariableAnimation repeat="1">
             <AniFrame value="0" time="0" varSpeedFlag="QuadFun_InOut"/>
             <AniFrame value="720" time="5000" varSpeedFlag="QuadFun_InOut"/>
         </VariableAnimation>
     </Var>
     <Image name="fengche" y="#h-1310" x="#w/2-132" alignV="bottom" align="center" src="fengche.png" angle="#changchui" pivotY="250" pivotX="250"> </Image>

     <!--飘带-->
     <Image name="piaodai" y="#h-903" x="1023" alignV="bottom" align="center" src="piaodai/piaodai_0.png">
         <SourcesAnimation repeat="4">
             <Source src="piaodai/piaodai_0.png" time="0"/>
             <Source src="piaodai/piaodai_1.png" time="40"/>
             ......
             <Source src="piaodai/piaodai_31.png" time="1240"/>
             <Source src="piaodai/piaodai_32.png" time="1280"/>
        </SourcesAnimation>
    </Image>

</CommonWallpaper>