jplayer / jPlayer

jPlayer : HTML5 Audio & Video for jQuery
http://jplayer.org/
Other
4.6k stars 1.47k forks source link

Can I make audio play in a specific range? #396

Open muzichen opened 6 years ago

muzichen commented 6 years ago

For example, If I want to make the audio play from 2.0s - 9.3s. I listened to timeupdate event, but the current time will larger than 9.3s before I pause the audio sometimes. Does anyone tell me how I can do this?

MartinDawson commented 6 years ago

@muzichen What do you mean 2.0 - 9.3? The volume is from 0 - 1.

If you never want to have volume go above 0.5 for example then you listen to the volumechange event and do this:

var maxVolume = 0.5;

volumechange: function(e) {
    if (e.jPlayer.options.volume > maxVolume ) {
         $("#myjPlayer").jPlayer("volume", maxVolume );
    }
}

In future ask these on stackoverflow. More likely for an answer than here.

muzichen commented 6 years ago

@MartinDawson 2.0 - 9.3 is the time of audio, not volume.

MartinDawson commented 6 years ago

@muzichen Sorry I mis-read your question. It's a bit unclear what you are asking, why does pausing the audio have anything to do with playing it in a specific range?

TimeUpdate gets fired every 250ms. This should be more than enough.

play : function(e) {
    $("#myjPlayer").jPlayer("play", 2 );
},
timeupdate: function(e) {
    if (e.jPlayer.options.currentTime > 9.3) {
         $("#myjPlayer").jPlayer("pause" );
    }
}

When the user starts playing the media, call the play function again at the 2 second mark. If the time goes over 9.3. Stop playing.

Is this what you wanted?

muzichen commented 6 years ago

@MartinDawson If the audio's current time is 9.5s, now, if is true. But, if 9.3s-9.5s the audio is also played.I want to find a way to solve this problem.

MartinDawson commented 6 years ago

@muzichen It's unclear what you are asking. Please ask on stackoverflow with a full example of what you mean.