Search code examples
javascriptjqueryhtmlaudiojplayer

Override negative remaining time in jPlayer


I was wondering if there was any way within the jPlayer plugin where you could override the remaining time text within the jp-duration div. Simply put I just want to remove the - that comes before the minutes/seconds. So instead of -03:26 I just want 03:26. Is there any pre-built functionality that would allow me to do this or would some custom script need to be written to accomplish what I'm looking to do?

JSFiddle

HTML

<div id="jquery_jplayer_1" class="jp-jplayer"></div>
<div id="jp_container_1" class="jp-audio" role="application" aria-label="media player">
    <div class="jp-type-single">
        <div class="jp-gui jp-interface">
            <div class="jp-volume-controls">
                <button class="jp-mute" role="button" tabindex="0">mute</button>
                <button class="jp-volume-max" role="button" tabindex="0">max volume</button>
                <div class="jp-volume-bar">
                    <div class="jp-volume-bar-value"></div>
                </div>
            </div>
            <div class="jp-controls-holder">
                <div class="jp-controls">
                    <button class="jp-play" role="button" tabindex="0">play</button>
                    <button class="jp-stop" role="button" tabindex="0">stop</button>
                </div>
                <div class="jp-progress">
                    <div class="jp-seek-bar">
                        <div class="jp-play-bar"></div>
                    </div>
                </div>
                <div class="jp-current-time" role="timer" aria-label="time">&nbsp;</div>
                <div class="jp-duration" role="timer" aria-label="duration">&nbsp;</div>
                <div class="jp-toggles">
                    <button class="jp-repeat" role="button" tabindex="0">repeat</button>
                </div>
            </div>
        </div>
        <div class="jp-details">
            <div class="jp-title" aria-label="title">&nbsp;</div>
        </div>
        <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>

JS

$(document).ready(function() {

    $("#jquery_jplayer_1").jPlayer({
        ready: function(event) {
            $(this).jPlayer("setMedia", {
                title: "Bubble",
                m4a: "http://jplayer.org/audio/mp3/Miaow-07-Bubble.mp3",
                oga: "http://jplayer.org/audio/ogg/Miaow-07-Bubble.ogg"
            });
        },
        swfPath: "http://jplayer.org/latest/dist/jplayer",
        supplied: "mp3, oga",
        wmode: "window",
        useStateClassSkin: true,
        autoBlur: false,
        smoothPlayBar: true,
        keyEnabled: true,
        remainingDuration: true,
        toggleDuration: true
    });
});                                      

Solution

  • Unfortunately negative remaining time is hard-coded and cannot be controlled via options.

    The simplest solution would be to download jPlayer latest release and modify dist/jquery.jplayer.js as follows:

    Replace the following line:

    durationText = (remaining > 0 ? '-' : '') + this._convertTime(remaining);
    

    with:

    durationText = this._convertTime(duration);
    

    Optionally you can minify modified file (for example, here).

    Finally you would need to include modified file instead of the original version on your page.