我继承了一个使用jPlayer的网络播放器。它适用于播放音频文件,但我试图在用户播放曲目时设置一些隐藏的字段,而我似乎无法获得绑定到jPlayer中任何事件的内容。我已经使用类似的代码绑定到h1标签上的click事件,它工作正常,但jplayer没有。也没有错误。我从jPlayer的文档中获得了绑定示例。 以下是我正在尝试做的事情的片段:
$(document).ready(function () {
//listener for playing the file
$("#jquery_jplayer_1").bind($.jPlayer.event.play, function (event) {
alert('play');
});
});
这是我的HTML:
<div id="jquery_jplayer_1" class="jp-jplayer"></div>
<div id="jp_container_1" class="jp-audio" >
<div class="jp-type-single">
<div id="htmlPlayer" style="display: none">
<audio id="audioPlayer" controls style="width:100%;">
<source id="mp3Source" type="audio/mp3" />
</audio>
</div>
<div class="htmlHidePoint" style="display: none">
<div class="jp-gui jp-interface">
<ul class="jp-controls">
<li><a href="javascript:;" onclick="javascript:alert('test');" class="jp-play" tabindex="1">play</a></li>
<li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
<li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>
<li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>
<li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>
<li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>
</ul>
<div class="jp-progress">
<div class="jp-seek-bar">
<div class="jp-play-bar"></div>
</div>
</div>
<div class="jp-volume-bar">
<div class="jp-volume-bar-value"></div>
</div>
<div class="jp-time-holder">
<div class="jp-current-time"></div>
<div class="jp-duration"></div>
<ul class="jp-toggles">
<li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>
<li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>
</ul>
</div>
</div>
</div>
<div class="jp-title">
<ul>
<li><span id="songname">No Song Selected</span></li>
</ul>
<div class="under">
<ul>
<li><a href="#" onclick="ViewTranscript();return false;" onkeypress="ViewTranscript();return false;" tabindex="2">Transcript</a></li>
<li><a href="#" onclick="ViewDowloadOptions();return false;" onkeypress="ViewDowloadOptions();return false;" tabindex="2">Download</a></li>
</ul>
</div>
</div>
<div class="htmlHidePoint" style="display: none">
<div class="jp-no-solution">
<span>Update Required</span>
To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.
</div>
</div>
</div>
</div>
实际的源文件是通过jPlayer方法中的error选项加载的:
error: function (event) {
if (event.jPlayer.error.type == 'e_url_not_set') {
$(this).jPlayer("setMedia", {
mp3: '<%=ResolveUrl("~/Handlers/Podcasts.ashx") %>?command=ZipPodcast&PodcastID=' + selectedPodcast.ItemID + '&options=audio'
});
$(this).jPlayer("play");
}
},
答案 0 :(得分:0)
显示jPlayer的html。确保ID正确无误。
尝试在选项上指定它:
$("#jquery_jplayer_1").jPlayer({
play: function() {
alert('hi');
}
});
您是否在使用选项初始化jPlayer之前或之后绑定了什么?
绑定时页面上是否有jPlayer?
答案 1 :(得分:0)
您的代码没有任何问题,您创建活动的方式是正确的,通常会弹出CREATE PROCEDURE [dbo].[udsp_CheckIfColumExist](@DBName Varchar(1000),@ColName Varchar(1000),@TableName Varchar(1000),@ServerName Varchar(1000))AS
DECLARE @SqlStr VARCHAR(MAX) = ''
IF @ServerName <> ''
SET @ServerName = '['+@ServerName+'].'
SET @SqlStr ='SELECT COUNT(1) IsExist FROM '+ @ServerName + @DBName+'.sys.columns
c join '+ @ServerName + @DBName +'.sys.tables t on t.OBJECT_ID = c.OBJECT_ID
WHERE c.name = N'''+@ColName +''' AND t.name = N''' +@TableName +''''
EXEC(@SqlStr)
。
尝试将您的语句置于jPlayer实例化之下。如果它不起作用,可能是因为实例化由于某些原因而没有成功。也许用于获取dom的选择器是错误的等等......
alert('play')
同时尝试将事件作为$("#jquery_jplayer_1").jPlayer()
$("#jquery_jplayer_1").bind($.jPlayer.event.play, function (event) {
alert('hi');
});
方法的选项,如Martin Mazza Dawson的回答所述