抖音开放平台Logo
开发者文档
“/”唤起搜索
控制台
  • JS API 列表
  • 基础
  • TTML
  • 网络
  • 媒体
  • 图片
  • 录音
  • 音频
  • 视频
  • tt.chooseVideo
  • tt.saveVideoToPhotosAlbum
  • tt.canIUseVideoFormat
  • tt.prerenderVideo
  • tt.preloadVideo
  • PreloadVideoTask
  • tt.chooseMedia
  • tt.createVideoContext
  • VideoContext
  • VideoContext 概述
  • VideoContext.play
  • VideoContext.pause
  • VideoContext.stop
  • VideoContext.requestFullScreen
  • VideoContext.seek
  • VideoContext.exitFullScreen
  • VideoContext.setWaterMark
  • VideoContext.getMediaVolume
  • VideoContext.setMediaVolume
  • VideoContext.playbackRate
  • tt.createLivePlayerContext
  • LivePlayerContext
  • 相机
  • 特效相机
  • Canvas 录制
  • rtc-room 实时通信
  • 地图
  • 文件
  • 数据缓存
  • 地理位置
  • 设备
  • 画布
  • 界面
  • 页面导航
  • 开放接口
  • 行业开放
  • 第三方平台
  • 其它
  • 生活服务(即将废弃)
  • VideoContext.setMediaVolume
    收藏
    我的收藏

    基础库 2.65.0 开始支持本方法,低版本需做兼容处理,这是一个异步方法。

    设置音量。

    前提条件
    业务背景
    使用限制
    注意事项
    支持沙盒
    相关教程

    语法

    VideoContext.setMediaVolume(options)

    参数说明

    options 为 object 类型,属性如下:

    属性名类型默认值必填说明最低支持版本
    valuenumber
    要设置的音量值,范围 [0, 1],精度到小数点后 1 位
    2.65.0
    successfunction
    接口调用成功的回调函数
    2.65.0
    failfunction
    接口调用失败的回调函数
    2.65.0
    completefunction
    接口调用结束的回调函数(调用成功、失败都会执行)
    2.65.0

    回调成功

    object 类型,属性如下:

    属性名类型说明最低支持版本
    errMsgstring
    "VideoContext.setMediaVolume:ok"
    2.65.0

    回调失败

    object 类型,属性如下:

    属性名类型说明最低支持版本
    errMsgstring
    "VideoContext.setMediaVolume:fail" + 详细错误信息
    2.65.0

    扫码体验

    请使用字节宿主APP扫码

    代码示例

    开发者工具中预览

    <video id="video" src="https://sf1-ttcdn-tos.pstatp.com/obj/ttfe/test/test-upload.mp4"></video> <button bindtap="setMediaVolume">setMediaVolume</button>
    Page({ data: {}, setMediaVolume() { const videoContext = tt.createVideoContext("video"); videoContext.setMediaVolume({ value: 1, success: (res) => { console.log("setMediaVolume success: ", res); }, fail: (res) => { console.log("setMediaVolume fail: ", res); }, complete: (res) => { console.log("setMediaVolume complete: ", res); }, }); }, });