请选择 进入手机版 | 继续访问电脑版
帖子
帖子
用户
博客
课程
12下一页
返回列表 发新帖
显示全部楼层
216
帖子
5
勋章
5893
Y币

mp3Recorder模块demo示例

[复制链接]
发表于 2019-7-5 12:21:23
mp3Recorder模块封装在iOS、Android下录音直接生成mp3,统一2个平台的录音生成文件,方便双平台之间的交互,减少录音完成后再转码的过程;同时提供分贝波形图显示UI。

点击进入模块详情

  1. <!DOCTYPE html>
  2. <html>

  3. <head>
  4.     <title>Module Develop</title>
  5.     <meta charset="utf-8">
  6.     <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  7.     <style type="text/css">
  8.         html,
  9.         body {
  10.             height: 100%
  11.         }

  12.         body {
  13.             background-color: #fff;
  14.             margin: 0;
  15.         }

  16.         #wrap {
  17.             height: 100%;
  18.             position: relative;
  19.         }

  20.         #header {
  21.             padding-top: 20px;
  22.             background-color: #5082c2;
  23.             height: 44px;
  24.             position: relative;
  25.         }

  26.         #header h1 {
  27.             font-size: 20px;
  28.             height: 44px;
  29.             line-height: 44px;
  30.             margin: 0em;
  31.             color: #fff;
  32.             margin-left: 100px;
  33.             margin-right: 100px;
  34.             text-align: center;
  35.         }

  36.         #main {
  37.             display: -webkit-box;
  38.             -webkit-box-orient: vertical;
  39.             -webkit-box-pack: center;
  40.         }

  41.         a.button {
  42.             display: -webkit-box;
  43.             -webkit-box-orient: vertical;
  44.             -webkit-box-pack: center;
  45.             -webkit-box-align: center;
  46.             height: 32px;
  47.             margin: 8px;
  48.             background-color: rgba(240, 240, 240, 1.0);
  49.             border-color: rgba(220, 220, 220, 1.0);
  50.             border-width: 2px;
  51.             border-style: solid;
  52.         }

  53.         a.active {
  54.             background-color: rgba(240, 240, 240, 0.7);
  55.         }
  56.     </style>
  57. </head>

  58. <body>
  59.     <div id="wrap">
  60.         <div id="main">
  61.             <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
  62.             <a class="button" tapmode="active" onclick="_addEventListener()">监听录音</a>
  63.             <a class="button" tapmode="active" onclick="startRecord()">开始录音</a>
  64.             <a class="button" tapmode="active" onclick="pauseRecord()">暂停录音</a>
  65.             <a class="button" tapmode="active" onclick="resumeRecord()">恢复录音</a>
  66.             <a class="button" tapmode="active" onclick="stopRecord()">停止录音</a>
  67.             <a class="button" tapmode="active" onclick="openVoiceLine()">打开曲线</a>
  68.             <a class="button" tapmode="active" onclick="closeVoiceLine()">关闭曲线</a>
  69.             <a class="button" tapmode="active" onclick="setDecibels()">设置分贝值</a>
  70.             <a class="button" tapmode="active" onclick="playAudio()">播放录音</a>
  71.             <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
  72.         </div>
  73.     </div>
  74. </body>
  75. <script>

  76.     apiready = function() {

  77.     }

  78.     var mp3Path;

  79.     function _addEventListener() {
  80.         var demo = api.require('mp3Recorder');
  81.         demo.addEventListener(function(ret, err) {
  82.             if (ret.evenType == 'endRecord') {
  83.                 mp3Path = ret.data.path;
  84.             }
  85.             api.toast({
  86.                 msg: JSON.stringify(ret)
  87.             });
  88.         });
  89.     }

  90.     function startRecord() {
  91.         var demo = api.require('mp3Recorder');
  92.         demo.startRecord({
  93.             channel: 2, //声道支持:1 单声道 2 立体声道
  94.             sampleRates: 44100, //采样率
  95.         }, function(ret, err) {
  96.             api.toast({
  97.                 msg: JSON.stringify(ret)
  98.             });
  99.         });
  100.     }

  101.     function pauseRecord() {
  102.         var demo = api.require('mp3Recorder');
  103.         demo.pauseRecord(function(ret, err){
  104.             api.toast({ msg: JSON.stringify(ret) });
  105.         });
  106.     }

  107.     function resumeRecord() {
  108.         var demo = api.require('mp3Recorder');
  109.         demo.resumeRecord(function(ret, err){
  110.             api.toast({ msg: JSON.stringify(ret) });
  111.         });
  112.     }

  113.     function stopRecord() {
  114.         var demo = api.require('mp3Recorder');
  115.         demo.stopRecord(function(ret, err) {
  116.             api.toast({
  117.                 msg: JSON.stringify(ret)
  118.             });
  119.         });
  120.     }

  121.     function openVoiceLine() {
  122.         var demo = api.require('mp3Recorder');
  123.         demo.openVoiceLine({
  124.             rect: {
  125.                 x: 0,
  126.                 y: 0,
  127.                 w: api.frameWidth,
  128.                 h: api.frameHeight / 3
  129.             },
  130.             fixedOn: api.frameName,
  131.             fixed: true,
  132.             isTransparent: false, //背景是否透明(透明时可以穿透点击视图)
  133.         }, function(ret, err) {
  134.             alert(JSON.stringify(ret));
  135.         });
  136.     }

  137.     function closeVoiceLine() {
  138.         var demo = api.require('mp3Recorder');
  139.         demo.closeVoiceLine(function(ret, err) {
  140.             api.toast({
  141.                 msg: JSON.stringify(ret)
  142.             });
  143.         });
  144.     }

  145.     function setDecibels() {
  146.         var demo = api.require('mp3Recorder');
  147.         var random = getRandom(0, 60);
  148.         demo.setDecibels({
  149.             decibel: random
  150.         }, function(ret, err) {
  151.             api.toast({
  152.                 msg: JSON.stringify(ret)
  153.             });
  154.         });
  155.     }

  156.     function getRandom(min, max) {
  157.         var r = Math.random() * (max - min);
  158.         var re = Math.round(r + min);
  159.         re = Math.max(Math.min(re, max), min)
  160.         return re;
  161.     }

  162.     function playAudio() {
  163.         api.startPlay({
  164.             path: mp3Path
  165.         }, function(ret, err) {

  166.         });
  167.     }
  168. </script>

  169. </html>
复制代码


44
帖子
0
勋章
149
Y币
如何设置录制时间
216
帖子
5
勋章
5893
Y币
自己弄一个定时器。。
75
帖子
2
勋章
378
Y币
版主,那个设置分贝值具体是有什么作用
216
帖子
5
勋章
5893
Y币
你可以做曲线动态展示咯。。
0
帖子
0
勋章
2
Y币
怎么var demo = api.require('mp3Recorder') 里的demo是undefined?
我的是webapp,还没有购买授权,是测试版
audioRecorder可以使用,但这个不行,是什么原因呢?
216
帖子
5
勋章
5893
Y币
要native
0
帖子
0
勋章
5893
Y币

支持一下
63
帖子
0
勋章
314
Y币
不错的模块!
8
帖子
0
勋章
35
Y币
java.lang.NullPointerException: Attempt to invoke virtual method \'void com.clam314.lame.DataEncodeThread.addChangeBuffer(short[], int)\' on a null object reference\n\tat com.clam314.lame.Mp3Recorder$1.run(Mp3Recorder.java:116)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)\n\tat java.lang.Thread.run(Thread.java:833)\n

使用中发现部分机型会报错,麻烦看看
12下一页
您需要登录后才可以回帖 登录

本版积分规则