跳转至

声音

兼容

支持浏览器范围:

(1) IE9+、Edge、Chrome 49+、Firefox 52+、Safari 等主流桌面版浏览器
​(2) Android 4.4+ 系统的默认浏览器以及微信浏览器
​(3) iOS Safari 浏览器以及微信浏览器

引用

<script src="http://cdn.ronghub.com/Libamr-2.2.5.min.js"></script>
<script src="http://cdn.ronghub.com/RongIMVoice-2.2.6.js"></script>
<script src="https://cdn.ronghub.com/Libamr-2.2.5.min.js"></script>
<script src="https://cdn.ronghub.com/RongIMVoice-2.2.6.js"></script>

代码示例: https://rongcloud.github.io/websdk-demo/voice.html

初始化

RongIMLib.RongIMVoice.init();

播放

/*
音频格式: base64 格式的 AMR
完整示例音频: https://cdn.ronghub.com/voice-amr-base64.json
*/
var audioFile = 'IyFBTVIKLNEafAAeef/hgmeAH8AD...';
// 音频文件长度   
var duration = audioFile.length / 1024;
// 预加载
RongIMLib.RongIMVoice.preLoaded(audioFile, function(){
    // 播放声音
  RongIMLib.RongIMVoice.play(audioFile, duration);
});

停止播放

RongIMLib.RongIMVoice.stop(audioFile);