后浪云百度小程序教程:InnerAudioContext
- InnerAudioContext
- 方法参数
- 支持格式
- 示例
- 图片示例
- 代码示例 1:实例方法全集
- 代码示例 2:属性全集
- 方法参数
InnerAudioContext
解释:swan.createInnerAudioContext 的返回值。
方法参数
方法 | 参数 | 必填 | 说明 |
---|---|---|---|
src |
String |
否 |
音频的数据链接,用于直接播放,仅支持绝对路径 |
startTime |
Number |
否 |
开始播放的位置(单位:s),默认 0 |
autoplay |
Boolean |
否 |
是否自动开始播放,默认 false |
loop |
Boolean |
否 |
是否循环播放,默认 false |
obeyMuteSwitch |
Boolean |
否 |
是否遵循系统静音开关,默认 true,当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音。仅在 iOS 生效 |
duration |
Number |
是 |
当前音频的长度(单位:s),只有在当前有合法的 src 时返回 |
currentTime |
Number |
是 |
当前音频的播放位置(单位:s),只有在当前有合法的 src 时返回,时间不取整,保留小数点后 6 位 |
paused |
Boolean |
是 |
当前状态。true:表示暂停或停止,false:表示正在播放 |
volume |
Number |
否 |
音量,范围 0~1 |
支持格式
格式 | iOS | Android |
---|---|---|
flac |
否 |
是 |
amr |
否 |
是 |
wma |
否 |
是 |
ogg |
否 |
是 |
ape |
否 |
是 |
mp4 |
否 |
是 |
m4a |
是 |
是 |
wav |
是 |
是 |
mp3 |
是 |
是 |
aac |
是 |
是 |
aiff |
是 |
否 |
caf |
是 |
否 |
示例
扫码体验
代码示例
请使用百度APP扫码
图片示例
代码示例 1:实例方法全集
在开发者工具中打开
在开发者工具中打开
在 WEB IDE 中打开
- SWAN
- JS
<view class="wrap">
<view class="card-area">
<button type="primary" bindtap="play">play</button>
<button type="primary" bindtap="pause">pause</button>
<button type="primary" bindtap="stop">stop</button>
<button type="primary" bindtap="seek">seek</button>
<button type="primary" bindtap="destroy">destroy</button>
</view>
</view>
代码示例 2:属性全集
在开发者工具中打开
在开发者工具中打开
在 WEB IDE 中打开
- JS
Page({
onLoad() {
const innerAudioContext = swan.createInnerAudioContext();
innerAudioContext.src = 'http://vd3.bdstatic.com/mda-ic7mxzt5cvz6f4y5/mda-ic7mxzt5cvz6f4y5.mp3';
innerAudioContext.startTime = 120;
innerAudioContext.autoplay = true;
innerAudioContext.loop = true;
// 一般设置obeyMuteSwitch为false,否则用户在系统静音的情况下,会认为api不能播放;
innerAudioContext.obeyMuteSwitch = false;
innerAudioContext.duration = 120;
innerAudioContext.currentTime = 90;
innerAudioContext.paused = true;
innerAudioContext.volume = 0.5;
}
});
版权声明:
作者:后浪云
链接:https://www.idc.net/help/186568/
文章版权归作者所有,未经允许请勿转载。
THE END