This repository has been archived by the owner on Nov 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 495
/
voice.html
74 lines (61 loc) · 2.2 KB
/
voice.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>voice</title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
</head>
<body>
<link rel="stylesheet" href="./res/rongcloud.css">
<script type="text/javascript" src="./lib/jquery-3.1.1.js"></script>
<!-- IE9下 swfobject 报错问题解决 -->
<!--[if !IE]><!-->
<script src="./lib/Libamr-2.2.5.min.js"></script>
<!--<![endif]-->
<script type="text/javascript" src="./lib/RongIMVoice-2.2.6.js"></script>
<!-- 引入base64编码的 amr 音频数据 -->
<script src="./res/voice-amr-base64.json"></script>
<a href="https://github.com/rongcloud/websdk-demo/blob/master/voice.html" class="get-source">获取源码</a>
<h1>声音库</h1>
<h2><a href="http://www.rongcloud.cn/docs/web.html#声音库">http://www.rongcloud.cn/docs/web.html#声音库</a></h2>
<div>支持范围:
<p>(1)IE9+、Windows Edge、Chrome、Firefox、Safari 等主流桌面版浏览器</p>
<p>(2)iOS Safari、iOS 微信浏览器 </p>
<p>(3)Android 4.4+ 默认浏览器、Android 微信浏览器</p>
</div>
<button class="voiceInfo" messageUId="5FNN-5MIH-S1VP-FT2O">播放测试语音1 base64 </button>
<button class="voiceInfo" messageUId="5FNN-5MSJ-068O-EPDH">播放测试语音2 base64</button>
<script>
/*
初始化声音库
*/
var RongIMVoice = RongIMLib.RongIMVoice;
RongIMVoice.init();
/*
* play() 播放音频消息
* 参数 voice 为 amr 格式的 base64
* 示例: voice = "IyFBTVIKLNEafAAeef/hgmeAH8AD...";
*/
function play(voice){
if(voice){
var duration = voice.length/1024; // 音频持续大概时间(秒)
RongIMVoice.preLoaded(voice, function(){
RongIMVoice.play(voice,duration);
});
}else{
console.error('请传入 amr 格式的 base64 音频文件');
}
}
/*
* messageData 为音频示例数据,在 voice-amr-base64.json 中
* 通过监听 button 的点击事件获取 消息的唯一标示 messageUId
* 根据 messageUId 获取到 音频消息的 base64 数据,然后执行 play() 方法
*/
$(".voiceInfo").on("click",function(){
var messageUId = $(this).attr('messageUId');
var voiceData = messageData[messageUId].content.content; //获取 base64 音频文件
play(voiceData);
});
</script>
</body>
</html>