jsp页面加入背景音乐 已加入 但用javascript控制其播放和停止时有点问题
jsp页面中使用object标签加入背景音乐代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<%@ page isELIgnored="false"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<% String contextPath = request.getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="expires" content="0" />
<script type="text/javascript" src="js/jquery/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/jquery/jquery-plugin-util.js"></script>
<title>jsp测试背景音</title>
<script type="text/javascript">
/**
* 播放警告音
*/
function broadcastWarnSounds(){
alert('start');
/** 解决 IE、firefox、chrome浏览器兼容问题 */
var player = document.getElementById("Player");
if(document.all){
player.start();
}else if(navigator.userAgent.indexOf('Firefox') > 0 || navigator.userAgent.indexOf('Chrome') > 0){
player.controls.start();
//$('param[name="autostart"]').attr('value','true');
}
}
/**
* 停止警告音
*/
function stopWarnSound(){
alert('stop');
/** 解决 IE、firefox、chrome浏览器兼容问题 */
var player = document.getElementById("Player");
if(document.all){
player.stop();
}else if(navigator.userAgent.indexOf('Firefox') > 0 || navigator.userAgent.indexOf('Chrome') > 0){
player.controls.stop();
}
}
</script>
<!-- <embed id="Player" src="mid/fc.mp3" type="application/x-mplayer2" autostart="true" width="200px" width="200px" loop="true" hidden="false"/> -->
</head>
<body>
<a href="javascript:void(0);" onclick="broadcastWarnSounds();">播放</a>
<a href="javascript:void(0);" onclick="stopWarnSound();">停止</a>
<!-- 背景音 OBJECT标签嵌入MediaPlayer 支持 .mp3、.wma -->
<object id="Player" name="Player" data="mid/fc.mp3" type="application/x-mplayer2" width="0" height="0">
<param name="src" value="mid/fc.mp3"/>
<param name="autostart" value="true"/>
<param name="loop" value="-1"/>
</object>
</body>
</html>
dome测试时用的是html 也是这种方式 没问题 IE、firefox、chrome都正常 可控制播放和停止
但是将其移至到jsp中后就出问题了,在jsp中只有‘停止’时是正常的, 点击‘播放’时 js控制台报:
TypeError: Object [object Object] has no method 'start'
这是咋子回事啊 望高人指点啊
好长时间没来csdn了 就这么点分了 大家见谅啊 --------------------编程问答--------------------
--------------------编程问答-------------------- 人工置顶!在线等待中 --------------------编程问答--------------------
<?xml version="1.0" encoding="utf-8" ?>???删除
<%@ page isELIgnored="false"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<% String contextPath = request.getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">改为<html>
<head>
你的意思是 让我尽量和html的内容一致?? 我刚才试了下 还是不行啊 --------------------编程问答-------------------- jsp上面的头信息会对我有影响么? <?xml version="1.0" encoding="utf-8" ?> 这个也要删除? --------------------编程问答-------------------- 那是xml文件的头文件 --------------------编程问答--------------------
把它删了 问题依旧 好郁闷 到底哪出问题了 --------------------编程问答-------------------- 大家帮忙看看吧 谢谢了
补充:Java , Web 开发