一段在网页上播放mp3语音的代码

在网页上直接播放语音,只要安装了flash播放器就可以用:


var VoicePlayer = {
        player: null,
        player_id : 'voice_player',
        voice_box_id : 'voice_box',
        //准备dom结构
        ready: function() {
                if (VoicePlayer.player !== null) {return;}

                var voice_box = document.createElement('div');
                voice_box.id = VoicePlayer.voice_box_id;

                if (!-[1,]) {
                    voice_box.innerHTML = '<object width="1" height="1" type="application/x-shockwave-flash" data="soundPlay.swf" id="'+ VoicePlayer.player_id +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" style="visibility: visible;"><param name="movie" value="soundPlay.swf"/></object>';
                } else {
                    voice_box.innerHTML = '<object width="1" height="1" type="application/x-shockwave-flash" data="soundPlay.swf" id="'+ VoicePlayer.player_id +'" style="visibility: visible;"></object>';
                }
                document.body.appendChild(voice_box);
                if (typeof swfobject !== 'undefined') {
                    VoicePlayer.player = swfobject.getObjectById(VoicePlayer.player_id);
                }
        },
        //播放
        //url为音频文件路径
        play: function(soundUrl) {
                if (typeof soundUrl === 'undefined') return;
                if (VoicePlayer.player === null) {
                        VoicePlayer.ready();
                }

                VoicePlayer.player.playSound(soundUrl);
        }
};

//VoicePlayer.ready();



阅读更多
个人分类: Javascript技术应用
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭