<! doctype html> <html> <head> <메타 charset = utf-8> <title> 나침반 예 </title> <script type = text/javaScript charset = utf-8 src = cordova.js> </script> <script type = text/javaScript charset = utf-8> document.addeventListener (deviceReady, ondeviceReady, false); 함수 ondeviceReady () {} var my_media = null; var mediatimer = null; 함수 playaudio (src) {my_media = new Media (SRC, OnSuccess, onerror); my_media.play (); if (mediatimer == null) {mediatimer = setInterval (function () {my_media.getCurrentPosition (// 成功回调 함수 (위치) {if (position> -1) {setaudioposition ((위치/1000)+Sec);}} // (함수 (e) {console.log (pos = +e); }} 함수 pauseaudio () {if (my_media) {my_media.pause (); }} 함수 stopaudio () {if (my_media) {my_media.stopaudio (); } ClearInterVal (Mediatimer); Mediatimer = null; } function onsuccess () {console.log (playaudio () : 오디오 성공); } 함수 setaudioposition (position) {document.getElementById ( 'audio_position'). innerHtml = 위치; } // 错误的回调 funture onerror (error) {alert ( 'code :'+error.code+'/n'+'메시지 :'+error.message+'/n'); } </script> </head> <hod> <a href =# onclick = playaudio ( 'http://example.com/audio.mp3');> 오디오 </a> <a href =# onclick = pauseaudio ();> 오디오 재생 일시 중지 </a> <a href =# onclick = stopaudio ();> 오디오 재생 중지 </a> <p id = audio_position> </p> </body> </html>
以上这篇使用 PhoneGap ap ap, 希望能给大家一个参考, 也希望大家多多支持 vevb 武林网。