我想用Javascript播放jPlayer,但它不會從Javascript播放;我必須手動點擊<button>
來播放它。Javascript - 如何從JavaScript中播放jplayer?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script type="text/javascript" src="http://jplayer.org/latest/dist/jplayer/jquery.jplayer.min.js"></script>
<script type="text/javascript">
function click_me_to_play() {
$('#play').trigger('click');
}
$(document).ready(function(){
$("#jquery_jplayer_1").jPlayer({
ready: function() {
$(this).jPlayer("setMedia", {
title: "Big Buck Bunny",
m4v: "http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v",
//ogv: "http://www.jplayer.org/video/ogv/Big_Buck_Bunny_Trailer.ogv",
//poster: "http://www.jplayer.org/video/poster/Big_Buck_Bunny_Trailer_480x270.png"
});
},
swfPath: "/js",
supplied: "m4v, ogv",
cssSelectorAncestor: "",
cssSelector: {
title: "#title",
play: "#play",
pause: "#pause",
stop: "#stop",
mute: "#mute",
unmute: "#unmute",
currentTime: "#currentTime",
duration: "#duration"
},
size: {
width: "320px",
height: "180px"
}
});
});
</script>
<style>
div.jp-jplayer {
border:1px solid #009be3;
}
</style>
</head>
<body onload="click_me_to_play();">
<p>
<button id="play">play</button>
</p>
<div id="jquery_jplayer_1" class="jp-jplayer"></div>
</body>
<html>
NO。我試過它從來沒有工作。它不是重複的,所有的舊例子都不起作用。 – YumYumYum
它不是自動播放。我想從javascript中播放它,而不是從Html/html5按鈕播放。 – YumYumYum
好吧,但在文檔中的一個答案中,他們引用了http://jplayer.org/latest/developer-guide/#jPlayer-play'$(id).jPlayer(「play」,[Number:time]) :jQuery' –