找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 小程序开发 查看内容

微信小程序播放音频

作者:模板之家 2018-1-2 09:01 8593人关注

今天做微信小程序涉及到播放音频文件: 使用audio标签来绑定音频路径 view plain copy audio id = audioid src = {{vidioUrl}} binderror = audioError bindplay = audioPlay bindeneded = playEnd bindtimeupdate ...

今天做微信小程序涉及到播放音频文件:

使用audio标签来绑定音频路径

 

[html] view plain copy
 
  1. <audio id='audioid' src='{{vidioUrl}}' binderror="audioError" bindplay="audioPlay" bindeneded="playEnd" bindtimeupdate="timeUpdate"> </audio>  

目前没有做到播放下一首的功能,只有暂停和播放。

最上面的播放条是通过progress的percent来实现的,

 

[html] view plain copy
 
  1. <progress percent="{{currtRate}}" stroke-width="2" activeColor="#ffd200" backgroundColor="#bcbcbc"  />  
通过currtRate来实现播放条的已播放长度

界面:

 

[html] view plain copy
 
  1. <view class="ub-ver info-container" style="height:5em;">  
  2.  <!-- 音频播放 -->  
  3.      <view class='ub fonts12 align-items-center' >  
  4.      <view>{{currentTime}}</view>  
  5.      <view class="umw-6"></view>  
  6.      <view class='ub-f1'>  
  7.        <progress percent="{{currtRate}}" stroke-width="2" activeColor="#ffd200" backgroundColor="#bcbcbc"  />  
  8.           <!-- {{vidioUrl}} -->  
  9.      </view>  
  10.      <view class="umw-6"></view>  
  11.      <view>{{duration}}</view>  
  12.    </view>    
  13.  <audio id='audioid' src='{{vidioUrl}}' binderror="audioError" bindplay="audioPlay" bindeneded="playEnd" bindtimeupdate="timeUpdate"> </audio>  
  14.      
  15.    <view class='ub ub-f1 align-items-center' style="justify-content:center">  
  16.   
  17.        <view  class="icon-bofanglist align-items-center" style="background:url('http://inheater-bbs.oss-cn-shenzhen.aliyuncs.com/xcx/icons/bofanglist.png') no-repeat;background-size: contain" bindtap="listClick">  
  18.          </view>  
  19.          <view class="umw1-5"></view>  
  20.          <view wx:if="{{flags}}" class="icon-play align-items-center" style="background:url('http://inheater-bbs.oss-cn-shenzhen.aliyuncs.com/xcx/icons/pause.png') no-repeat;background-size: contain" bindtap="pause">   
  21.          </view>  
  22.           <view wx:if="{{flagp}}" class="icon-next align-items-center" style="background:url('../../images/zanting@3x.png') no-repeat;background-size: contain" bindtap="play">  
  23.          </view>  
  24.          <view class="umw1-5"></view>  
  25.          <view  class="icon-next align-items-center" style="background:url('http://inheater-bbs.oss-cn-shenzhen.aliyuncs.com/xcx/icons/next.png') no-repeat;background-size: contain">  
  26.          </view>  
  27.    </view>  
  28.  </view>  

js文件:

 

[html] view plain copy
 
  1. onLoad: function (options) {  
  2.    var that =  邀请

路过

雷人

握手

鲜花

鸡蛋
原作者: 模板之家 来自: 网络收集

全部回复(0)