FinClip为企业提供小程序生态圈技术产品,开发者可在FinClip小程序开发帮助中心找到相关FinClip小程序指引

# 媒体

# 图片

# saveImageToPhotosAlbum

基础库 2.0.7 开始支持,iOS版本 2.10.7,Android版本2.11.43

saveImageToPhotosAlbum(Object object)

保存图片到系统相册。

参数

Object object

属性 类型 默认值 必填 说明
filePath string 图片文件路径,可以是临时文件路径或永久文件路径,不支持网络图片路径
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数(当授权失败时,返回错误信息:fail unauthorized 用户未授予读取外部存储、读写外部存储权限)
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

ft.saveImageToPhotosAlbum({
  filePath: 'finfile://xxxx',
  success(res) { }
})

注意

  • 接口授权失败(iOS):
  1. 用户拒绝授权,会返回错误信息: unauthorized,用户未授予相册权限
  2. 宿主App禁止小程序主动申请权限,会返回错误信息:unauthorized disableauthorized,SDK被禁止申请相册权限
  • 接口授权失败(Android):
  1. 用户拒绝授权,会返回错误信息:unauthorized 用户未授予读取外部存储、读写外部存储权限
  2. 宿主App禁止小程序主动申请权限,会返回错误信息:unauthorized disableauthorized SDK被禁止了主动发起权限申请

# previewMedia

预览图片和视频。

参数

Object object

属性 类型 默认值 必填 说明
sources Array.<Object> 需要预览的资源列表
current number 0 当前显示的资源序号
showmenu boolean true 是否显示长按菜单,长按图片显示发送给朋友、收藏、保存图片、搜一搜、打开名片/前往群聊/打开小程序(若图片中包含对应二维码或小程序码)的菜单
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

object.sources 的结构

属性 类型 默认值 必填 说明
url String 图片或视频的地址
type String image 资源的类型,默认为图片
poster string 视频的封面图片

type 的合法值

说明 最低版本
image 图片
video 视频

# previewImage

基础库1.3.9开始支持,iOS版本2.1.23,Android版本2.1.38

previewImage(Object object)

在新页面中全屏预览图片。

参数

Object object

属性 类型 默认值 必填 说明
urls Array.<string> 需要预览的图片链接列表
current string urls 的第一张 当前显示图片的链接
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

ft.previewImage({
  current: '', // 当前显示图片的http链接
  urls: [] // 需要预览的图片http链接列表
})

# chooseImage

基础库1.3.9开始支持,iOS版本2.1.23,Android版本2.1.38

chooseImage(Object object)

从本地相册选择图片或使用相机拍照。

参数

Object object

属性 类型 默认值 必填 说明
count number 9 最多可以选择的图片张数
sizeType Array.<string> ['original', 'compressed'] 所选的图片的尺寸
sourceType Array.<string> ['album', 'camera'] 选择图片的来源
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数(当授权失败时,返回错误信息:fail unauthorized 用户未授予读取外部存储、读写外部存储权限)
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

object.sizeType 的合法值

说明
original 原图
compressed 压缩图

object.sourceType 的合法值

说明
album 从相册选图
camera 使用相机

object.success 回调函数

参数

Object res

属性 类型 说明
tempFilePaths Array.<string> 图片的本地临时文件路径列表
tempFiles Array.<Object> 图片的本地临时文件列表

res.tempFiles 的结构

属性 类型 说明
path string 本地临时文件路径
size number 本地临时文件大小,单位 B

示例代码

ft.chooseImage({
  count: 1,
  sizeType: ['original', 'compressed'],
  sourceType: ['album', 'camera'],
  success(res) {
    // tempFilePath可以作为img标签的src属性显示图片
    const tempFilePaths = res.tempFilePaths
  }
})

注意

  • 接口授权失败(iOS):
  1. 用户拒绝授权,会返回错误信息: unauthorized,用户未授予相册权限
  2. 宿主App禁止小程序主动申请权限,会返回错误信息:unauthorized disableauthorized,SDK被禁止申请相册权限
  • 接口授权失败(Android):
  1. 用户拒绝授权,会返回错误信息:unauthorized 用户未授予读取外部存储、读写外部存储权限
  2. 宿主App禁止小程序主动申请权限,会返回错误信息:unauthorized disableauthorized SDK被禁止了主动发起权限申请

# 视频

# createVideoContext

基础库 2.11.2 开始支持,iOS 版本 2.34.1,Android 版本 2.34.1 VideoContext ft.createVideoContext(string id, Object this)

创建 video 上下文 VideoContext 对象。

参数

string id

video 组件的 id

Object this

在自定义组件下,当前组件实例的this,以操作组件内 video 组件

返回值

VideoContext

# VideoContext 方法

VideoContext.play()

播放视频

VideoContext.pause()

暂停视频

VideoContext.stop()

停止视频

VideoContext.seek(number position)

跳转到指定位置

position 单位 s

VideoContext.sendDanmu(Object data)

发送弹幕

参数

Object data

属性 类型 默认值 必填 说明
text string 弹幕文字
color string 弹幕颜色

VideoContext.playbackRate(number rate)

设置倍速播放

倍率 rate,合法值 0.5/0.8/1.0/1.25/1.5/2

VideoContext.requestFullScreen(Object object)

进入全屏(IDE 不支持)

参数

Object object

属性 类型 默认值 必填 说明
direction number 设置全屏时视频的方向,不指定则根据宽高比自动判断。合法值:0、90、-90

VideoContext.exitFullScreen()

退出全屏(IDE 不支持)

VideoContext.showStatusBar()

显示状态栏,仅在iOS全屏下有效。

VideoContext.hideStatusBar()

隐藏状态栏,仅在iOS全屏下有效。

VideoContext.requestBackgroundPlayback()

进入后台音频播放模式(IDE 不支持)

VideoContext.exitBackgroundPlayback()

退出后台音频播放模式(IDE 不支持)

# 音频

# setInnerAudioOption

setInnerAudioOption(Object object) 设置 InnerAudioContext 的播放选项。设置之后对当前小程序全局生效。

参数

Object object

属性 类型 默认值 必填 说明
mixWithOther boolean true 是否与其他音频混播,设置为 true 之后,不会终止其他应用或微信内的音乐
obeyMuteSwitch boolean true (仅在 iOS 生效)是否遵循静音开关,设置为 false 之后,即使是在静音模式下,也能播放声音
speakerOn boolean true true 代表用扬声器播放,false 代表听筒播放,默认值为 true。
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

注意 为保证整体体验,speakerOn 为 true 时,客户端会忽略 mixWithOthers 参数的内容,强制与其它音频互斥 不支持在播放音频的过程中切换为扬声器播放,开发者如需切换可以先暂停当前播放的音频并记录下当前暂停的时间点,然后切换后重新从原来暂停的时间点开始播放音频

# createInnerAudioContext

InnerAudioContext ft.createInnerAudioContext()

创建 audio 上下文 InnerAudioContext 对象。

返回值

InnerAudioContext

# InnerAudioContext

InnerAudioContext 实例,可通过 ft.InnerAudioContext 获取。

属性

  • string src
    ​ 音频资源的地址,用于直接播放。

  • number startTime
    ​ 开始播放的位置(单位:s),默认为 0

  • boolean autoplay
    是否自动开始播放,默认为 false

  • boolean loop
    是否循环播放,默认为 false

  • number volume
    音量。范围 0~1。默认为 1

  • number playbackRate
    播放速度。范围 0.5-2.0,默认为 1。

方法

  • InnerAudioContext.play()
    播放

  • InnerAudioContext.pause()
    暂停。暂停后的音频再播放会从暂停处开始播放

  • InnerAudioContext.stop()
    停止。停止后的音频再播放会从头开始播放。

  • InnerAudioContext.seek(number position)
    跳转到指定位置​

  • InnerAudioContext.destroy()
    销毁当前实例

  • InnerAudioContext.onCanplay(function callback)
    监听音频进入可以播放状态的事件。但不保证后面可以流畅播放

  • InnerAudioContext.offCanplay(function callback)
    取消监听音频进入可以播放状态的事件

  • InnerAudioContext.onPlay(function callback)
    监听音频播放事件

  • InnerAudioContext.offPlay(function callback)
    取消监听音频播放事件

  • InnerAudioContext.onPause(function callback)
    监听音频暂停事件

  • InnerAudioContext.offPause(function callback)
    取消监听音频暂停事件

  • InnerAudioContext.onStop(function callback)
    监听音频停止事件

  • InnerAudioContext.offStop(function callback)
    取消监听音频停止事件

  • InnerAudioContext.onEnded(function callback)
    监听音频自然播放至结束的事件

  • InnerAudioContext.offEnded(function callback)
    取消监听音频自然播放至结束的事件

  • InnerAudioContext.onTimeUpdate(function callback)
    监听音频播放进度更新事件

  • InnerAudioContext.offTimeUpdate(function callback)
    取消监听音频播放进度更新事件

  • InnerAudioContext.onError(function callback)
    监听音频播放错误事件

  • InnerAudioContext.offError(function callback)
    取消监听音频播放错误事件

  • InnerAudioContext.onWaiting(function callback)
    监听音频加载中事件。当音频因为数据不足,需要停下来加载时会触发

  • InnerAudioContext.offWaiting(function callback)
    取消监听音频加载中事件

  • InnerAudioContext.onSeeking(function callback)
    监听音频进行跳转操作的事件

  • InnerAudioContext.offSeeking(function callback)
    取消监听音频进行跳转操作的事件

  • InnerAudioContext.onSeeked(function callback)
    监听音频完成跳转操作的事件

  • InnerAudioContext.offSeeked(function callback)
    取消监听音频完成跳转操作的事件

示例代码

// innerAudioContext.js
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
innerAudioContext.onPlay(() => {
  console.log('开始播放')
})
innerAudioContext.onError((res) => {
  console.log(res.errMsg)
  console.log(res.errCode)
})

# 录音

# getRecorderManager

RecorderManager ft.getRecorderManager()

获取全局唯一的录音管理器 RecorderManager

返回值

RecorderManager

# RecorderManager

全局唯一的录音管理器

方法

  • RecorderManager.start(Object object)
    开始录音

  • RecorderManager.pause()
    暂停录音

  • RecorderManager.resume()
    继续录音

  • RecorderManager.stop()
    停止录音

  • RecorderManager.onStart(function callback)
    监听录音开始事件

  • RecorderManager.onResume(function callback)
    监听录音继续事件

  • RecorderManager.onPause(function callback)
    监听录音暂停事件

  • RecorderManager.onStop(function callback)
    监听录音结束事件

  • RecorderManager.onError(function callback)
    监听录音错误事件

  • RecorderManager.onInterruptionBegin(function callback)
    监听录音因为受到系统占用而被中断开始事件。pause 事件在此事件后触发​

  • RecorderManager.onInterruptionEnd(function callback)
    监听录音中断结束事件。在收到 interruptionBegin 事件之后,小程序内所有录音会暂停,收到此事件之后才可再次录音成功。

注意

  • 接口授权失败(iOS):
  1. 用户拒绝授权,会返回错误信息: unauthorized,用户未授予麦克风权限
  2. 宿主App禁止小程序主动申请权限,会返回错误信息:unauthorized disableauthorized,SDK被禁止申请麦克风权限

# 相机

# createCameraContext

createCameraContext()

创建 camera 上下文 CameraContext 对象。

返回值

CameraContext

© 2022 FinClip with ❤