Last active
April 24, 2020 10:17
-
-
Save gaupoit/400efb9f825c17c9df79de85e35f11f4 to your computer and use it in GitHub Desktop.
Integrate PDA Videos with jPlayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
'use strict'; | |
$(document).ready(function () { | |
// Init jPlayer. | |
$("#jquery_jplayer_1").jPlayer({ | |
cssSelectorAncestor: "#jp_container_1", | |
swfPath: "/js", | |
supplied: "mp3, oga", | |
useStateClassSkin: true, | |
autoBlur: false, | |
smoothPlayBar: true, | |
keyEnabled: true, | |
remainingDuration: true, | |
toggleDuration: true | |
}); | |
// Example: we have the button with class name is track and data-mp3-id attribute storing the protected mp3 file. | |
// <button class="track" data-mp3-id="1">Play</button> | |
$('.track').click(function(evt) { | |
const src = $(this).attr('data-mp3-id'); | |
// It will generate the private link and pass it to jPlayer. | |
_generate_signed_url(src, function (mp3) { | |
if (!mp3) { | |
console.log('Cannot generate the private link.'); | |
} | |
$("#jquery_jplayer_1").jPlayer("setMedia", { | |
mp3, | |
waitForLoad: false, | |
}).jPlayer("play"); | |
}); | |
}); | |
function _generate_signed_url(src, cb) { | |
const rootDomain = ajax_obj.rest_url; | |
const url = rootDomain + 'puv/v1/private-link/' + src; | |
$.ajax({ | |
type: 'post', | |
dataType: 'json', | |
url: url, | |
success: function (response) { | |
cb(response); | |
} | |
}) | |
} | |
}); | |
})(jQuery); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment