前言:本项目基于github开源插件实现,该插件使用flash实现,兼容IE8以上浏览器

感谢michalstocki的分享该项目,github项目地址:https://github.com/michalstocki/FlashWavRecorder

博主修改后的项目下载地址:http://download.csdn.net/detail/eguid_1/9684124

1、要提交的表单(如果只需要上传文件,可以不需要)

<form id="uploadForm" name="uploadForm" action="audio/send" method="post">
<span>设备id:</span><input name="deviceId" value="0000007"><!-- 设备id -->
<span>音频格式:</span><input name="audio_format" value="wav"><!-- 音频格式 -->
</form>

2、修改表单名和上传的音频文件名

这两个参数用来修改上传的表单和要上传的已经录制好的音频文件名,与后台的文件接收的参数名一致

FWRecorder.uploadFormId = "#uploadForm";//要上传的表单

 FWRecorder.uploadFieldName = "audio_file";//上传文件的参数名

$(function () {
var $uploadStatus = $('#upload_status'),
$showLevelButton = $('.show_level'),
$hideLevelButton = $('.hide_level'),
$level = $('.control_panel .level'); var CLASS_CONTROLS = "control_panel";
var CLASS_RECORDING = "recording";
var CLASS_PLAYBACK_READY = "playback_ready";
var CLASS_PLAYING = "playing";
var CLASS_PLAYBACK_PAUSED = "playback_paused"; // Embedding flash object --------------------------------------------------------------------------------------------- setUpFormOptions();
var appWidth = 24;
var appHeight = 24;
var flashvars = {'upload_image': 'audioRecorder/upload.png'};
var params = {};
var attributes = {'id': "recorderApp", 'name': "recorderApp"};
swfobject.embedSWF("audioRecorder/recorder.swf", "flashcontent", appWidth, appHeight, "11.0.0", "", flashvars, params, attributes); // Handling FWR events ------------------------------------------------------------------------------------------------ window.fwr_event_handler = function fwr_event_handler() {
$('#status').prepend("<div class=\"recorder-event\">" + arguments[0] + "</div>");
var name, $controls;
switch (arguments[0]) {
case "ready":
var width = parseInt(arguments[1]);
var height = parseInt(arguments[2]);
FWRecorder.uploadFormId = "#uploadForm";//要上传的表单
FWRecorder.uploadFieldName = "audio_file";//上传文件的参数名
FWRecorder.connect("recorderApp", 0);
FWRecorder.recorderOriginalWidth = width;
FWRecorder.recorderOriginalHeight = height;
$('.save_button').css({'width': width, 'height': height});
break; case "no_microphone_found":
break; case "microphone_user_request":
recorderEl().addClass("floating");
FWRecorder.showPermissionWindow();
break; case "microphone_connected":
FWRecorder.isReady = true;
$uploadStatus.css({'color': '#000'});
break; case "permission_panel_closed":
FWRecorder.defaultSize();
recorderEl().removeClass("floating");
break; case "microphone_activity":
$('#activity_level').text(arguments[1]);
break; case "recording":
name = arguments[1];
$controls = controlsEl(name);
FWRecorder.hide();
setControlsClass($controls, CLASS_RECORDING);
break; case "recording_stopped":
name = arguments[1];
$controls = controlsEl(name);
var duration = arguments[2];
FWRecorder.show();
setControlsClass($controls, CLASS_PLAYBACK_READY);
$('#duration').text(duration.toFixed(4) + " 秒");
break; case "microphone_level":
$level.css({width: arguments[1] * 50 + '%'});
break; case "observing_level":
$showLevelButton.hide();
$hideLevelButton.show();
break; case "observing_level_stopped":
$showLevelButton.show();
$hideLevelButton.hide();
$level.css({width: 0});
break; case "playing":
name = arguments[1];
$controls = controlsEl(name);
setControlsClass($controls, CLASS_PLAYING);
break; case "playback_started":
name = arguments[1];
var latency = arguments[2];
break; case "stopped":
name = arguments[1];
$controls = controlsEl(name);
setControlsClass($controls, CLASS_PLAYBACK_READY);
break; case "playing_paused":
name = arguments[1];
$controls = controlsEl(name);
setControlsClass($controls, CLASS_PLAYBACK_PAUSED);
break; case "save_pressed":
FWRecorder.updateForm();
break; case "saving":
name = arguments[1];
break; case "saved":
name = arguments[1];
var data = $.parseJSON(arguments[2]);
if (data.status) {
$('#upload_status').css({'color': '#0F0'}).text(name + " 上传成功");
} else {
$('#upload_status').css({'color': '#F00'}).text(name + " 上传失败");
}
break; case "save_failed":
name = arguments[1];
var errorMessage = arguments[2];
$uploadStatus.css({'color': '#F00'}).text(name + " 失败: " + errorMessage);
break; case "save_progress":
name = arguments[1];
var bytesLoaded = arguments[2];
var bytesTotal = arguments[3];
$uploadStatus.css({'color': '#000'}).text(name + " 进展: " + bytesLoaded + " / " + bytesTotal);
break;
}
}; // Helper functions --------------------------------------------------------------------------------------------------- function setUpFormOptions() {
var gain = $('#gain')[0];
var silenceLevel = $('#silenceLevel')[0];
for (var i = 0; i <= 100; i++) {
gain.options[gain.options.length] = new Option(100 - i);
silenceLevel.options[silenceLevel.options.length] = new Option(i);
}
} function setControlsClass($controls, className) {
$controls.attr('class', CLASS_CONTROLS + ' ' + className);
} function controlsEl(name) {
return $('#recorder-' + name);
} function recorderEl() {
return $('#recorderApp');
} // Button actions ----------------------------------------------------------------------------------------------------- window.microphonePermission = function () {
recorderEl().addClass("floating");
FWRecorder.showPermissionWindow({permanent: true});
}; window.configureMicrophone = function () {
if (!FWRecorder.isReady) {
return;
}
FWRecorder.configure($('#rate').val(), $('#gain').val(), $('#silenceLevel').val(), $('#silenceTimeout').val());
FWRecorder.setUseEchoSuppression($('#useEchoSuppression').is(":checked"));
FWRecorder.setLoopBack($('#loopBack').is(":checked"));
}; });

3、后台接收文件

接收前端三个参数:deviceId,audio_format,audio_file
audio_file就是音频文件
public int sendAudioData(@RequestParam(value = "deviceId") String deviceId,
@RequestParam(value = "audio_format") String audio_format, @RequestParam("audio_file") MultipartFile file) {
boolean ret=false;
File tFile = null;
System.out.println(audio_format + "," + deviceId);
String fileName=null;
// 判断文件是否为空
if (file != null && !file.isEmpty()&&(fileName=file.getName()+System.currentTimeMillis())!=null) {
String filePath = Util.getRootPath() + fileName + ".wav";
System.out.println("文件保存路径:" +filePath);
tFile = new File(filePath); try {
// 转存文件
file.transferTo(tFile);
ret=true;
} catch (Exception e) {
e.printStackTrace();
}
}
if(ret=true){
return 0;
}
return -1;
}

4、最终效果

使用FlashWavRecorder实现浏览器录制wav音频和上传音频文件,兼容IE8以上浏览器的更多相关文章

  1. 兼容IE8以下浏览器input表单属性placeholder不能智能提示功能

    当前很多表单提示使用了表单属性placeholder,可这属性不兼容IE8以下的浏览器,我自己写了一个兼容处理js // 兼容IE8以下浏览器input不能智能提示功能 if(navigator.ap ...

  2. placeholder兼容方法(兼容IE8以上浏览器)

    //placeholder兼容方法(兼容IE8以上浏览器) var JPlaceHolder = { //检测 _check: function () { return 'placeholder' i ...

  3. [转]python3之paramiko模块(基于ssh连接进行远程登录服务器执行命令和上传下载文件的功能)

    转自:https://www.cnblogs.com/zhangxinqi/p/8372774.html 阅读目录 1.paramiko模块介绍 2.paramiko的使用方法 回到顶部 1.para ...

  4. 背景图片background-size兼容ie8以下浏览器解决

    背景图片不够大,然后就想到用background-size:100%; 测试浏览器的时候发现ie8以下不兼容,图片会自动填充平铺过去,然后出现背景不好看的现象.解决方法: background-ima ...

  5. 浏览器关闭、刷新、关闭标签事件,兼容IE8,chrome,firefox

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  6. vue项目中兼容ie8以上浏览器的配置

    1.首先需要在根目录的index.html文件加入如下代码 <meta http-equiv="X-UA-Compatible" content="IE=edge& ...

  7. Django积木块三——静态文件和上传文件

    静态文件和上传的文件 # 静态文件 STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), ) # ...

  8. Windows Phone 8初学者开发—第20部分:录制Wav音频文件

    原文 Windows Phone 8初学者开发—第20部分:录制Wav音频文件 原文地址:http://channel9.msdn.com/Series/Windows-Phone-8-Develop ...

  9. 多浏览器播放wav格式的音频文件

    html5的audio标签只在火狐下支持wav格式的音频播放,无法兼容IE和google , 使用audioplayer.js 基本上能支持大部分浏览器播放wav音频文件,经测试IE.火狐.googl ...

随机推荐

  1. seajs加载jquery提示$ is not a function

    jquery1.7以上的都支持模块化加载,只是jquery默认的是支持amd,不支持cmd.所以要用seajs加载jquery,需要稍微改下jquery 把 if (typeof define === ...

  2. [ SharePoint ADFS 开发部署系列 (一)]

    前言 本文完全原创,转载请说明出处,希望对大家有用. 随着企业信息化建设逐渐成熟,基于微软体系的企业内部系统架构在众多企业中得到应用,随之而来的用户统一身份认证(SSO)问题成为企业IT部门急需解决的 ...

  3. 学习Java之前操作环境的安装及配置

    1.根据自己的系统版本下载相应版本的JDK(Java开发运行时环境) 查看自己系统版本的方法:在桌面上右键计算机(win7,win10是此电脑,XP是我的电脑),点击属性,进入到计算机属性页面以后里面 ...

  4. linux性能之iostat

    在使用linux系统的过程中,总是可能需要当前io性能的状态信息是怎么样?这里就就是一下iostat,可以通过iostat来初步查看io的状态信息. 1.常用方式 iostat -xdk 1 10 或 ...

  5. copyWithZone 的使用方法

    1.简单复制只能实现浅拷贝:指针赋值,使两个指针指向相同的一块内存空间,操作不安全. 2. Foundation类已经遵守了<NSCopying>和 <NSMutableCopyin ...

  6. 中美HTML5市场发展的简单对比

    1. HTML5的中美发展与应用对比 2014年下半年,HTML5在中国火了.个人用它开展自媒体,散播鸡汤:广告公司靠它做市场营销,从中获利:还有大公司的广告部.企业新媒体部或转型的媒体,利用它进行各 ...

  7. Web 版 powerdesigner (Canvas) 技术分享

    演示地址:http://www.netuml.com:8088  <canvas></canvas>是HTML5出现的新标签,像所有的dom对象一样它有自己本身的属性.方法和事 ...

  8. linux下实时监测命令运行结果工具:watch

    watch是一个非常实用的工具,可以实时监测一些经常变化的命令结果或文件,而不需要手动一次一次的输入命令. 语法: watch [选项] [命令参数] 选项: -n :指定刷新间隔时间,默认2秒. - ...

  9. 学习笔记:javascript body常用事件

    Window 事件属性 针对 window 对象触发的事件(应用到 <body> 标签): 属性 值 描述 onafterprint script 文档打印之后运行的脚本. onbefor ...

  10. shell群发邮件脚本

    linux版本:CentOS  6.7        //可以使用lsb_release -a查看 一.修改/etc/mail.rc set from=123456@qq.com //你自己的真实邮箱 ...