Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
T treasure
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 12
    • Issues 12
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • FE
  • treasure
  • Issues
  • #228

Closed
Open
Created Mar 12, 2024 by xiao yanan@lredvjiDeveloper

小程序实现振动及音频功能

振动效果

直接调用微信提供的api(振动是有自带音效的)

  • wx.vibrateShort -- 短振动 / 15ms / 仅支持iphone7及以上和安卓机型
  • wx.vibrateLong -- 长振动 / 400ms

短音频效果

利用wx.createInnerAudioContext创建内部 audio 上下文 InnerAudioContext 对象。

wx.createInnerAudioContext({ 
	useWebAudioImplement: true // 短音频且需要频繁播放的最好将该项开启
}); 
  • 静音情况的处理 目前只支持ios静音状态下播放音效,

    wx.setInnerAudioOption({ // ios在静音状态下能够正常播放音效
    
    obeyMuteSwitch: true, // 是否遵循系统静音开关,默认为 true。当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音。
    
    success: function(e) {},
    
    fail: function(e) {},
    });
  • 音频链接src

支持云文件也支持本地文件 (本地文件一定要用绝对路径,不能用相对路径)

  • 播放/暂停

innerAudioContext.autoplay: 控制自动播放

innerAudioContext.loop: 控制循环播放

innerAudioContext.play() // 音频开始播放,若连续调用该方法不会中断,而是等当前播完才播下一次

innerAudioContext.pause() // 音频暂停,在当前进度暂停,再次播放从这里开始

innerAudioContext.stop() // 音频停止,下一次播放从头开始

  • 销毁实例

innerAudioContext.destroy(); // 由于音频资源不会自动释放,所以在不需要的时候需要进行手动销毁

Edited Mar 12, 2024 by xiao yanan
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking