简体   繁体   English

jplayer绑定似乎不起作用

[英]jplayer binding doesn't seem to work

I've inherited a web player that uses jPlayer. 我继承了使用jPlayer的网络播放器。 It works fine for playing audio files, but I'm trying to set some hidden fields when the user plays a track and I cannot seem to get something bound to any event in jPlayer. 它适合播放音频文件,但是当用户播放音轨时,我试图设置一些隐藏字段,而jPlayer中似乎无法绑定到任何事件。 I've used similar code to bind to a click event on an h1 tag and it works fine, but jplayer doesn't. 我已经使用类似的代码将其绑定到h1标签上的click事件,并且可以正常工作,但jplayer不能。 No errors either. 也没有错误。 I got the bind examples from jPlayer's documention. 我从jPlayer的文档中获得了绑定示例。 Here is a snippet of what I'm trying to do: 这是我要执行的操作的摘要:

 $(document).ready(function () {

    //listener for playing the file
    $("#jquery_jplayer_1").bind($.jPlayer.event.play, function (event) {

        alert('play');
    });
 });

Here is my html: 这是我的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>&nbsp;



The actual source files are loaded via the error option in the jPlayer method: 实际的源文件是通过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");
                }
            },

Show html for the jPlayer. 显示jPlayer的html。 Make sure the id is correct. 确保ID是正确的。

Try specifying it on options instead: 尝试改为在选项上指定它:

$("#jquery_jplayer_1").jPlayer({
  play: function() {
    alert('hi');
  }
});

Are you binding before or after the jPlayer is initialised with your options? 您是在使用选项初始化jPlayer之前还是之后绑定?

Is the jPlayer on the page when you bind? 绑定时页面上是否存在jPlayer?

There is nothing wrong on your code, the way you create the event is right, normally alert('play') will poping up. 代码没有错,创建事件的方式是正确的,通常会弹出alert('play')

Try to put your statements under the jPlayer instantiation. 尝试将您的语句放在jPlayer实例化下。 If it's not working it could be because the instantiation wasn't success due some reasons. 如果不起作用,可能是由于某些原因,实例化未成功。 maybe the selector used to fetch the dom is wrong, etc... 也许用来获取dom的选择器是错误的,等等。

$("#jquery_jplayer_1").jPlayer()
$("#jquery_jplayer_1").bind($.jPlayer.event.play, function (event) {
    alert('hi');
}); 

Also try to put the event as an options on jPlayer() method, as mentioned on answer by Martin Mazza Dawson 还要尝试将事件作为jPlayer()方法的一个选项,如Martin Mazza Dawson的回答所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM