h5语音播放(移动端)

摘要:
位置Divstyle=“height;float;font size;margin-top;color;00<divi=“过去的时间”>}&bclass=“routeIco”>转到此处<<};audio.pause();

<!--语音导航 start-->
<div style="border:0px solid red;100%;height:72px;position:relative;overflow-y: hidden;">
<img src="http://t.zoukankan.com/static/front/images/voice_play.png" />
<!--audio start-->
<audio src=${(sightSpotVo.voice)!}></audio>
<!--audio end-->
<div style="border:0px solid red;50%;height: 56px;float:left;margin-top: 16px;">
<div style="height:10px;float:right;font-size: 12px;margin-top: 8px;color:#8E8E8E;"><span id="time">00:00</span>/<span id="sumTime">00:00</span></div>
<div id="progress_bar">
<div id="pastime"></div>
</div>
</div>
<a href="http://t.zoukankan.com/wap/map.htm?type=${(userParam.type)!}&id=${(userParam.id)!}&singspotId=${(sightSpotVo.id)!}&isIt='flase'">
<b class="routeIco"></b>
<p>去这里</p>
</a>
</div>
<!--语音导航 end-->


//语音播放
var initAudio=function (){
var audio=document.getElementById("audio");
//播放按钮
var play=document.getElementById("play");
audio.load(); //音频加载
audio.addEventListener("canplaythrough", function() {
$("#sumTime").text(format(audio.duration));
});
audio.addEventListener('timeupdate',function(){
if (!isNaN(audio.duration)) {
var pastime = document.getElementById("pastime");
var widthline = Math.round(audio.currentTime)/Math.round(audio.duration) * 100;
pastime.style.width = widthline + "%";
$("#time").text(format(audio.currentTime));
};
},false);
play.onclick=function () {
if(audio.paused){
play.src="http://t.zoukankan.com/static/front/images/voice_pause.png";
audio.play();
playCount++;//播放次数+1
}else{
play.src="http://t.zoukankan.com/static/front/images/voice_play.png";
audio.pause();
}
}
//注册触摸滑动事件
$('#progress_bar').get(0).addEventListener('touchstart', touchMoveFunc, false);
$('#progress_bar').get(0).addEventListener('touchmove', touchMoveFunc, false);
$('#progress_bar').get(0).addEventListener('touchend', touchMoveFunc, false);
}
//触摸滑动
var touchMoveFunc=function(ev){
audioPorgress(ev);
}
//时间格式化
function format(value) {
var theTime = parseInt(value);// 秒
var theTime1 = 0;// 分
var theTime2 = 0;// 小时
if(theTime > 60) {
theTime1 = parseInt(theTime/60);
theTime = parseInt(theTime%60);
}
var result =(parseInt(theTime1)<10?"0"+parseInt(theTime1):parseInt(theTime1))+":"+(parseInt(theTime)<10?"0"+parseInt(theTime):parseInt(theTime));
if(theTime1 > 0) {
result =(parseInt(theTime1)<10?"0"+parseInt(theTime1):parseInt(theTime1))+":"+(parseInt(theTime)<10?"0"+parseInt(theTime):parseInt(theTime));
}
return result;
}
//调整播放进度条
function audioPorgress(event){
var dom=$('#progress_bar').get(0);
//var event = window.event || ev;
var touch = event.targetTouches[0];
var progressX = touch.pageX - dom.getBoundingClientRect().left;
audio.currentTime = parseInt(progressX/324*audio.duration);
}

免责声明:文章转载自《h5语音播放(移动端)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇uniapp画布基本使用解除docker文件限制下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

表与表之间建关系(约束)

目录 约束条件default默认值 unique唯一 primary key主键 auto_increment自增 表与表之间建关系 外键 表关系 一对多关系 多对多 一对一 修改表(了解) 复制表(了解) 约束条件 default默认值 # 补充知识点 插入数据的时候可以指定字段 create table t1( id int,...

JavaScript常用方法(转载)

只能是写限定的东西 代码如下:   只能是中文 <input onkeyup="value=value.replace(/[ -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9">   只能是英文和数字.屏蔽了输入法 <input onkeydown="if(event....

element-UI 表单图片判空验证问题

本文地址:http://www.cnblogs.com/veinyin/p/8567167.html  element-UI的表单验证似乎并没有覆盖到文件上传上面,当我们需要在表单里验证图片时,就会出现问题。 当图片为空时,点击保存,会出现提示。 但是当我上传图片后,提示并不会随着消失,而是仍然显示着,如下图 如果需要做到正常的表单验证,可以在 on-c...

网页图片很多时,加载完后再加载图片(defer:延迟加载)

图片影响页面加载速度,可以先加载完页面,再去加载图片。 defer:告诉浏览器,这里面的js代码不影响网页脚本解析,可以解析完html脚本再执行这段js代码(个人理解)。 网页代码:<img src="http://t.zoukankan.com/grey.gif" data-original="img/53a1820f5866c.png"/>...

Python学习日记(十九) 模块导入

模块导入 当文件夹中有这样一个自定义的command模块 在它的内部写下下列代码: print('这个py文件被调用!') def fuc(): print('这个函数被调用!') 然后我们在command模块中执行下列代码: import command #这个py文件被调用! 我们如果在这段程序中反复执行多次这一段代码,这一个文...

koa和egg项目webpack热更新实现

背景 在用Node.js+Webpack构建的方式进行开发时, 我们希望能实现修改代码能实时刷新页面UI的效果. 这个特性webpack本身是支持的, 而且基于koa也有现成的koa-webpack-hot-middleware 和 koa-webpack-dev-middleware 封装好的组件支持. 不过这里如果需要支持Node.js服务器端修改代码...