后浪云百度小程序教程: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

    示例

    扫码体验

    代码示例

    后浪云百度小程序教程:InnerAudioContext插图

    请使用百度APP扫码

    图片示例

    后浪云百度小程序教程:InnerAudioContext插图1

    代码示例 1:实例方法全集

    在开发者工具中打开

    在开发者工具中打开

    在 WEB IDE 中打开

    • SWAN
    • JS
     
     
     
    1. <view class="wrap">
    2. <view class="card-area">
    3. <button type="primary" bindtap="play">play</button>
    4. <button type="primary" bindtap="pause">pause</button>
    5. <button type="primary" bindtap="stop">stop</button>
    6. <button type="primary" bindtap="seek">seek</button>
    7. <button type="primary" bindtap="destroy">destroy</button>
    8. </view>
    9. </view>

    代码示例 2:属性全集

    在开发者工具中打开

    在开发者工具中打开

    在 WEB IDE 中打开

    • JS
     
     
     
    1. Page({
    2. onLoad() {
    3. const innerAudioContext = swan.createInnerAudioContext();
    4. innerAudioContext.src = 'http://vd3.bdstatic.com/mda-ic7mxzt5cvz6f4y5/mda-ic7mxzt5cvz6f4y5.mp3';
    5. innerAudioContext.startTime = 120;
    6. innerAudioContext.autoplay = true;
    7. innerAudioContext.loop = true;
    8. // 一般设置obeyMuteSwitch为false,否则用户在系统静音的情况下,会认为api不能播放;
    9. innerAudioContext.obeyMuteSwitch = false;
    10. innerAudioContext.duration = 120;
    11. innerAudioContext.currentTime = 90;
    12. innerAudioContext.paused = true;
    13. innerAudioContext.volume = 0.5;
    14. }
    15. });
    THE END