How to set song duration in $(id).jPlayer( "setMedia", Object: media )

359 views
Skip to first unread message

Dinusha De Silva

unread,
Apr 18, 2014, 10:59:54 AM4/18/14
to jpl...@googlegroups.com
Hi,
     I need to restrict the song play duration to 45 seconds. I found out that you can set the player duration using $(id).jPlayer( "setMedia", Object: media ) with the duration parameter. However I'm having trouble setting it.
Can anyone please provide me with a sample code.

Thank You.

Mark Panaghiston

unread,
Apr 18, 2014, 1:30:04 PM4/18/14
to jpl...@googlegroups.com
The duration property of the media object used in setMedia only affects the display. You could say the media is 30 seconds long, but if it is really 3 minutes long then it will go up to 3 minutes and the GUI will just look odd with the bar and odd times.
 
Example use so duration shows on page load... In the example, the piece of audio is 3 minutes, 29 seconds long:

$("#jquery_jplayer_1").jPlayer({
	ready: function (event) {
		$(this).jPlayer("setMedia", {
			title: "Bubble",
duration: 209,
  m4a: "http://jplayer.org/audio/m4a/Miaow-07-Bubble.m4a", oga: "http://jplayer.org/audio/ogg/Miaow-07-Bubble.ogg" }); }, swfPath: "js",
solution: "flash,html", supplied: "m4a, oga", wmode: "window" });

To do what you want though, you need to use the timeupdate event.
timeupdate: function (event) {
	if(event.jPlayer.status.currentTime > 45) {
		$(this).jPlayer("stop");
	});
},
Reply all
Reply to author
Forward
0 new messages