phonegap中播放音频的示例分析

这篇文章主要介绍phonegap中播放音频的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

创新互联公司主要从事成都网站建设、网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务漳州,十余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575

实例如下:

 

     
         
        Compass Example 
  
         
         
            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'); 
            } 
              
         
     
  
     
        Play Audio 
        Pause Playing Audio 
        Stop Playing Audio 
        

          

以上是“phonegap中播放音频的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


网站名称:phonegap中播放音频的示例分析
文章URL:http://azwzsj.com/article/ipjpep.html