<!DOCTYPE html> <html lang="en"> <head> <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" id="viewport" name="viewport"> <meta charset="utf-8"> <title></title> <script type="text/javascript" src="./js/jquery-1.11.1.js"></script> <script language="javascript" src="./js/cordova_ios.js" > </script> <script language="javascript" src="./cordova_plugins.js" > </script> <style type="text/css"> input{width:200px;height:50px;display:block} </style> </head> <body> <div class="app"> <h1>Apache Cordova</h1> <div id="deviceready" class="blink"> <p id="test">操作提示</p><!--这里会显示录音操作中的各个变化--> <input type="button" value="录音" id="luyin" /> <input type="button" value="录音完成" id="luyin_finish" /> <input type="button" value="录音播放" id="luyin_bofang" /> <input type="button" value="录音上传 " id="luyin_upload" /> </div> </div> <script type="text/javascript"> var mediaRec; var recTimeMax = 10; var recTime = 0; var recordFile = "documents://myrecording.wav"; var recordFIlePath=''; document.addEventListener("deviceready", function onDeviceReady() { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, function fail(){}); }, false); var gotFS = function (fileSystem) { fileSystem.root.getFile("myrecording.wav", { create: true, exclusive: false }, //create if it does not exist function success(entry) { recordFIlePath = entry.toURI(); }, function fail() {} ); }; //开始录音 function recordAudio() { var src = recordFile; mediaRec = new Media(src, onSuccess, onError); // Record audio mediaRec.startRecord(); // Stop recording after 10 sec recTime = 0; var recInterval = setInterval(function() { recTime = recTime + 1; if (recTime >= recTimeMax) { clearInterval(recInterval); mediaRec.stopRecord(); mediaRec.release(); } }, 1000); } // onSuccess Callback // function onSuccess() { alert('success'); console.log("recordAudio():Audio Success"); } // onError Callback // function onError(error) { alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); } //========== //录音完成 function recordFinish() { recTime = recTimeMax; } //播放audio function playAudio(url) { // Play the audio file at url var my_media = new Media(url, // success callback function() { console.log("playAudio():Audio Success"); }, // error callback function(err) { console.log("playAudio():Audio Error: "+err); }); // Play audio my_media.play(); } //\\ //上传 function uloadRecord(){ var win = function (r) { alert("Code = " + r.responseCode); console.log("Response = " + r.response); console.log("Sent = " + r.bytesSent); } var fail = function (error) { alert("An error has occurred: Code = " + error.code); console.log("upload error source " + error.source); console.log("upload error target " + error.target); } var options = new FileUploadOptions(); options.fileKey = "file"; options.fileName = "myrecording.wav"; options.mimeType = "audio/wav"; var ft = new FileTransfer(); ft.upload(recordFIlePath, encodeURI("http://192.168.1.101/upload_record/index.php"), win, fail, options); } //为按钮绑定 touchstart(点击) 事件 $("#luyin").click(function(){ //实例化录音类 recordAudio(); //开始录音 $("#test").html("开始录音"); }); //录音 完成 $('#luyin_finish').click(function(){ recordFinish(); }); //录音 播放 $('#luyin_bofang').click(function(){ playAudio(recordFile); }); //录音 上传 $('#luyin_upload').click(function(){ uloadRecord() }); </script> </body> </html>
需要添加 cordova 的 file 和 filetransfer 插件
相关推荐
预算应用 v1.0 混合预算应用程序 - >cordova,在android 4.1中测试的angularjs
cordova-screenshot cordova截屏插件 document.addEventListener("deviceready", init, false); function init() { document.querySelector("#share").addEventListener("touchend", function() { navigator....
科尔多瓦-插件-iOS-XHRcordova-ios 6+ File XHR插件关于最初,此插件是其他两个插件的合并,并与cordova-ios 6+兼容。 自从进行了修改以来, 的代码现在已被完全删除。 它保留在此处作为原始参考。 如果时间允许,...
在存在iOS项目添加Cordova实现H5调用设备相册
ionic 借助插件 cordova-plugin-wechat cordova-plugin-qqsdk 实现微信分享 QQ分享 微博分享
JiaCordova是为了让项目对于Cordova引入更加方便快捷的一个封装式插件,插件中已经集成的关于Cordova跟其一些常用的第三库,对于Cordova的配置模板也进行整理,且封装从服务端下载ZIP包进行解压到沙盒文件夹中,利用...
vue-cli-plugin-cordova ...$ npm run cordova-prepare # prepare for build (you can run this command, when you checkouted your project from GIT, it's like npm install) 安卓 $ npm run cor
IOS版本的demo,内附详细说明,官方文档。
cordova plugin fingerprint-aio
前端项目-ng-cordova,Cordova with AngularJS Goodness
cordova-ios,开发IOS所必须的资源
科尔多瓦-插件-iosrtc iOS插件公开了 。 有关cordova-plugin-iosrtc的问题和讨论的。 用于报告问题并请求新功能(请不要将Bug Tracker用于问题或问题,... cordova-ios > = 4.5.1 第三方支持的图书馆 WebRTC W3C v1.
mMedia(Millennial Media)插件专业版 通过JavaScript本地在...如果与Intel XDK一起使用:项目-> CORDOVA 3.X混合移动应用程序设置->插件和权限->第三方插件->添加第三方插件->从Web获取插件,输入: Name: mMediaP
于插件 注意:兼容每个版本的VueJS(1.x和2.x)... cordova-plugin-camera cordova-plugin-device cordova-plugin-geolocation cordova-plugin-contacts cordova-plugin-chrome-apps-sockets-tcp cordova-plugin-sms 如
instabug-cordova-plugin-ios-framework 包含iOS Instabug.framework和Instabug.bundle文件的存储库。 这是由于npm问题破坏了符号链接。 ( ) SDK版本:1.7
cordova plugin add @ahovakimyan/cordova-plugin-wkwebviewxhrfix 或从github安装 cordova plugin add https://github.com/AraHovakimyan/cordova-plugin-wkwebviewxhrfix 笔记 此插件不依赖于其他任何插件,并且...
有些项目一开始是原生开发的,后期可能需要进行混合开发。这里提供一个在原生工程中引入Cordova工程的demo。具体导入方法可以参考我在csdn上写的博文http://blog.csdn.net/e20914053/article/details/50170487
前端开源库-anysql-cordova-sqliteanysql cordova sqlite,anysql api的cordova sqlite实现
如果电话号码在“设置”->“关于电话”->“状态”->“我的电话号码”上可用,它应该可以工作。 安装 使用cordova-cli 如果您使用的是 ,请安装: cordova plugin add ...
cordova-plugin-app-update App updater for Cordova/PhoneGap Demo Try it yourself: Just clone and install this demo. cordova-plugin-app-update-DEMO :tada: 如果喜欢它,请别忘了给我一颗鼓励的星 Support ...