网站地图    收藏   

主页 > 前端 > css教程 >

Phonegap-----Media - html/css语言栏目:html.css - 自学

来源:自学PHP网    时间:2015-04-14 14:51 作者: 阅读:

[导读] Everything in the code:[html]!DOCTYPE htmlhtmlheadtitleMedia Example/titlescript type=text/javascript charset=utf-8 src=cordova.js/scriptscript type=text/javascript......

Everything in the code:


[html]
<!DOCTYPE html> 
<html> 
<head> 
<title>Media Example</title> 
<script type="text/javascript" charset="utf-8" src="cordova.js"></script> 
<script type="text/javascript" charset="utf-8"> 
 
    var my_media = null; 
    var mediaTimer = null; 
    var music_src = "/android_asset/www/music.mp3"; 
     
    document.addEventListener("deviceready",onDeviceReady,false); 
     
    function onDeviceReady(){ 
        playAudio(music_src); 
    } 
 
    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) + " sec"); 
                       } 
                   }, 
                   // error callback 
                   function(e){ 
                       console.log("Error getting pos=" + e); 
                       setAudioPosition("Error: " + e); 
                   } 
               ); 
            }, 
            1000); 
        } 
    } 
     
    function pauseAudio() 
    { 
        if(my_media){ 
            my_media.pause(); 
        } 
    } 
     
    function continueAudio() 
    { 
        if(my_media){ 
            my_media.play() 
        } 
    } 
     
    function stopAudio(){ 
        clearInterval(mediaTimer); 
        mediaTimer = null; 
         
        if(my_media){ 
            my_media.stop(); 
             
            // on an Android device,it is important to release the media 
            media.release(); 
        } 
    } 
     
    function onSuccess(){ 
        console.log("playAudio():Audio Success"); 
    } 
     
    function onError(error){ 
        alert('code: ' + error.code    + '\n' + 
              'message: ' + error.message + '\n'); 
    } 
     
    function setAudioPosition(position){ 
        document.getElementById('audio_position').innerHTML = position; 
    } 
</script> 
</head> 
<body> 
    <a href="#" onClick="playAudio(music_src);">Play Audio</a> 
    <a href="#" onClick="pauseAudio();">Pause Playing Audio</a> 
    <a href="#" onClick="continueAudio();">continue Playing Audio</a> 
    <a href="#" onClick="stopAudio();">Stop Playing Audio</a> 
    <p id="audio_position"></p> 
</body> 
</html> 

<!DOCTYPE html>
<html>
<head>
<title>Media Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

    var my_media = null;
 var mediaTimer = null;
 var music_src = "/android_asset/www/music.mp3";
 
    document.addEventListener("deviceready",onDeviceReady,false);
 
 function onDeviceReady(){
  playAudio(music_src);
 }

 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) + " sec");
        }
       },
       // error callback
       function(e){
        console.log("Error getting pos=" + e);
        setAudioPosition("Error: " + e);
       }
      );
   },
   1000);
  }
 }
 
 function pauseAudio()
 {
  if(my_media){
   my_media.pause();
  }
 }
 
 function continueAudio()
 {
  if(my_media){
   my_media.play()
  }
 }
 
 function stopAudio(){
  clearInterval(mediaTimer);
  mediaTimer = null;
  
  if(my_media){
   my_media.stop();
   
   // on an Android device,it is important to release the media
   media.release();
  }
 }
 
 function onSuccess(){
  console.log("playAudio():Audio Success");
 }
 
 function onError(error){
  alert('code: ' + error.code    + '\n' +
        'message: ' + error.message + '\n');
 }
 
 function setAudioPosition(position){
  document.getElementById('audio_position').innerHTML = position;
 }
</script>
</head>
<body>
    <a href="#" onClick="playAudio(music_src);">Play Audio</a>
    <a href="#" onClick="pauseAudio();">Pause Playing Audio</a>
    <a href="#" onClick="continueAudio();">continue Playing Audio</a>
    <a href="#" onClick="stopAudio();">Stop Playing Audio</a>
    <p id="audio_position"></p>
</body>
</html>

Comments welcome!!!!!!

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论