-
Notifications
You must be signed in to change notification settings - Fork 188
13 手机音量模块
Xiaomi-Yule edited this page Jan 20, 2021
·
1 revision
手机音量
Export: public
Doc_name: 手机音量模块
Doc_index: 13
Doc_directory: system
Example
import {System} from "miot"
import {VolumeChangeEvent} from "miot"
...
System.volume.startVolume().then((res) => {
alert(`getStartVolume: ${ JSON.stringify(res) }`);
});
...
System.volume.stopVolume().then(() => {})
...
-
miot/system
-
static
-
.VolumeChangeEvent ⇒
number
-
.VolumeChangeEvent ⇒
-
inner
-
~IVolume
-
.getVolumeInfo() ⇒
[ 'Promise' ].<object>
-
.startVolume(hideSystemSlider) ⇒
[ 'Promise' ].<json>
-
.stopVolume() ⇒
[ 'Promise' ].<json>
-
.getVolumeInfo() ⇒
-
~IVolume
-
static
监听音量变化事件
Kind: static constant of miot/system
Returns: number
- volume 当前音量
Since: 10045
Example
VolumeChangeEvent.onVolumeChange.addListener((result) => {
console.log(result);
});
Kind: inner interface of miot/system
-
~IVolume
-
.getVolumeInfo() ⇒
[ 'Promise' ].<object>
-
.startVolume(hideSystemSlider) ⇒
[ 'Promise' ].<json>
-
.stopVolume() ⇒
[ 'Promise' ].<json>
-
.getVolumeInfo() ⇒
获取音量信息
Kind: instance method of IVolume
Returns: [ 'Promise' ].<object>
- result:
成功时:{"code":0, "data":xxx},data.volume:number,设备当前音量,取值在0.0-1.0之间
失败时:{"code":-1, "message":"xxx" };
Since: 10045
Example
System.volume.getVolumeInfo().then((res) => {
if (res && res.data) {
alert(`getSystemVolumeInfo success,volume:${ res.data.volume }`);
} else {
alert(`getSystemVolumeInfo fail,${ JSON.stringify(res) }`);
}
}).catch((error) => {
alert(`getSystemVolumeInfo fail,${ JSON.stringify(error) }`);
});
});
开始监听音量变化
Kind: instance method of IVolume
Returns: [ 'Promise' ].<json>
- 成功时:{code:0,message:'success'}
Since: 10045
Param | Type | Description |
---|---|---|
hideSystemSlider | Object |
是否隐藏系统的音量进度条,默认不隐藏 |
Example
System.volume.startVolume({hideSystemSlider:true}).then((res) => {
alert(`getStartVolume: ${ JSON.stringify(res) }`);
}).catch((error) => {
alert(`getStartVolume: ${ JSON.stringify(error) }`);
});
停止监听量变化
Kind: instance method of IVolume
Returns: [ 'Promise' ].<json>
- 成功时:{code:0,message:'success'}
Since: 10045
Example
System.volume.stopVolume().then((res) => {
alert(`getStopVolume: ${ JSON.stringify(res) }`);
}).catch((error) => {
alert(`getStopVolume: ${ JSON.stringify(error) }`);
});