Playback Length 30 second samples

1,009 views
Skip to first unread message

John

unread,
May 2, 2011, 6:16:05 PM5/2/11
to jPlayer: HTML5 Audio & Video for jQuery
I've got my JPlayer up and running perfectly. Its Great!!
I've got it running off a dynamic playlist from my database and mp3's
on the server.

Just want to know, is it possible to restrict the playback length to
30 seconds or even a certain percentage of the track.

The reason being it will be at the discretion of the artist weather to
let the public listen to the whole song or just a sample of it. So I
will be querying the database as to what the artist has chosen and
then executing it in the player if necessary.

I've been looking at moving the playhead to even half way through but
I'm not sure where to implement it.

$("#jquery_jplayer_2").jPlayer("playHead", 10);

Is what I am trying to do possible?!

Mark Panaghiston

unread,
May 3, 2011, 7:34:30 AM5/3/11
to jpl...@googlegroups.com
Hello John,

The playHead method is not really the best one to use. Its behaviour depends on how much has loaded and generally before anything has loaded, it has no effect.

To control the start time, use the play method with the optional time parameter. The following command starts playback from 10 seconds.

$(...).jPlayer("play", 10);

To control the end time, you would setup an event handler on the timeupdate event. This will check the currentTime and then perform the action you want when it occurs. I will use a pause for this example and it will pause after 30 seconds of play.

$(...).bind($.jPlayer.event.timeupdate, function(event) {
  if(event.jPlayer.status.currentTime > 30) {
    $(this).jPlayer("pause");
  }
});

You should note that the media URLs will still be accessible by anyone who uses a web dev tool such as Firebug as they can see the URLs, or through inspecting the code in most cases. They could then bypass your limiting solution.

The best way for cases like this is to produce 2 versions, the normal version that you sell and the short preview that you allow easy access to.

Other solution include restricting the referrer on the server to your site. While far from perfect, it can help stop direct access to the media files outside your site. Group members have already given such details on how to do this. Try searching the group if you are interested.

Best regards,
Mark P.



John

unread,
May 6, 2011, 6:42:48 AM5/6/11
to jPlayer: HTML5 Audio & Video for jQuery
Thanks Mark that works!! I understand the risks that you pointed out..
I might try making short sample files at a later date. Thanks for your
help

On May 3, 12:34 pm, Mark Panaghiston <mark.panaghis...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages