9

微信小程序开发实战(28):播放、暂停、停止声音

 3 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/108396383
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

微信小程序开发实战(28):播放、暂停、停止声音

使用wx.playVoice方法可以播放指定的音频文件,该方法需要设置一个filePath属性,用来指定音频文件的路径。使用wx.pauseVoice方法可以暂停当前音频文件的播放,暂停后,再次调用wx.playVoice方法,会从暂停的位置继续播放。如果要想从头播放音频文件,需要下调用wx.stopVoice方法停止音频文件的播放,再次调用wx.playVoice方法就会从头开始播放音频文件。小程序只允许同时播放一个音频文件,如果播放当前音频时,前一个音频正在播放,将终止前一个音频的播放。

下面的代码改进了上一节的程序,在停止录音后,可以播放、暂停和停止录制的音频。

index.wxml

index.js


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK