当前位置:首页 / 网页制作 / html5教程 / phonegap播放音频介绍
phonegap播放音频介绍
芯晴素材特效 分类:html5教程 发布日期:2018-05-11

这次给大家带来phonegap播放音频详解,phonegap播放音频详解的注意事项有哪些,下面就是实战案例,一起来看一下。

实例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!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>

版权信息:本站所有资源仅供学习与参考,请勿用于商业用途,如有侵犯您的版权,请及时联系821794221#qq.com(#换@),我们将尽快处理。

您可能在找这些

热门素材

jq左右透明遮罩图片切换网页下载

2017-03-15   浏览:186

一款漂亮的蓝色风格CSS竖向菜单

2013-01-06   浏览:8009

jq二维码生成插件

2017-03-19   浏览:146

html5酒店预订日期选择手机日历

2017-03-14   浏览:500

HTML5手机登录注册表单网页下载

2017-03-14   浏览:345

jq双重滚动效果

2017-03-19   浏览:337

jq多图图片通栏切换网页下载

2017-03-15   浏览:346

jQuery可自定义高度图片瀑布流网页下载

2017-03-14   浏览:101

音乐专辑推荐展示JS网页下载

2017-03-12   浏览:217

漂亮的JS滑动门式图片自动切换效果

2013-01-14   浏览:9505

表单效果之输入框随鼠标点击换色

2013-01-03   浏览:8126

[酷] 模仿Windows飞行视窗的登陆框

2012-12-31   浏览:8245