您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

phonegap播放音频详解

2024/3/15 8:40:18发布17次查看
这次给大家带来phonegap播放音频详解,phonegap播放音频详解的注意事项有哪些,下面就是实战案例,一起来看一下。
实例如下:
<!doctype html>  <html>     <head>          <meta charset="utf-8">          <title>compass example</title>             <script type="text/javascript" charset="utf-8" src="cordova.js"></script>          <script type="text/javascript" charset="utf-8">              document.addeventlistener(deviceready, ondeviceready, false);                 function ondeviceready() {              }                             var my_media=null;              var mediatimer=null;                             function playaudio(src){                  my_media=new media(src,onsuccess,onerror);                  my_media.play();                                     if(mediatimer==null){                      mediatimer=setinterval(function(){                          my_media.getcurrentposition(                              //成功回调                              function(position){                              if(position>-1){                                  setaudioposition((position/1000)+sec);                              }                          },                          //错误回调                          function (e){                              console.log(error getting pos=+e);                              setaudioposition(error: +e);                          }                          );                      },1000);                  }              }                             function pauseaudio(){                  if(my_media){                      my_media.pause();                  }              }                             function stopaudio(){                  if(my_media){                      my_media.stopaudio();                  }                  clearinterval(mediatimer);                  mediatimer=null;              }                             function onsuccess(){                  console.log(playaudio():audio success);              }                             function setaudioposition(position){                  document.getelementbyid('audio_position').innerhtml=position;              }                 //错误的回调               function onerror(error) {                  alert('code:'+error.code+'\n'+'message:'+error.message+'\n');              }                         </script>      </head>         <body>          <a href="#" onclick="playaudio('http://example.com/audio.mp3');">play audio</a>          <a href="#" onclick="pauseaudio();">pause playing audio</a>          <a href="#" onclick="stopaudio();">stop playing audio</a>          <p id="audio_position"></p>      </body>     </html>
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
pushstate、popstate操作url的方法
不刷新的前提下怎样改变当前url的代码
以上就是phonegap播放音频详解的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product