Skip to content

Commit

Permalink
improvements to strict audio player
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhunt committed Nov 2, 2022
1 parent 04f9d6e commit 896f747
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Change List
=========
Versions 3.1.60 (Build 2022082200)
- updated strict multiplayer to remember play position

Version 3.1.59 (Build 2022082200)
- Added strict multiplayer
- Added lightbox, Buncee, Flip, Wordwall, Quizlet templates
Expand Down
3 changes: 2 additions & 1 deletion classes/awstools.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,9 @@ function fetch_s3client() {
return $this->s3client;
}

function get_presigned_upload_url($mediatype, $minutes = 30, $key, $iosvideo = false) {
function get_presigned_upload_url($mediatype, $minutes, $key, $iosvideo = false) {
$s3client = $this->fetch_s3client();
if(!$minutes){$minutes=30;}
//Get bucket
$bucket = '';
switch ($mediatype) {
Expand Down
2 changes: 1 addition & 1 deletion presets/pw-multiplayeraudio.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"MultiPlayerAudio-Widget","key":"pw-multiplayeraudio","version":"1.0.2","instructions":"This is an HTML5 audio player that will only play the audio a preconfigured number of times. Insert an audio player or audio link between the tags.","showatto":"1","showplayers":"0","requirecss":"","requirejs":"","shim":"","defaults":"canplaycount=2,quiz_strict_mode=false|true","amd":"1","body":"<div id='@@AUTOID@@_container'></div>\n<div id=\"@@AUTOID@@_original\" style=\"display: none\">\n@@canplaycount@@ \n@@quiz_strict_mode@@ \n@@URLPARAM:attempt@@\n@@URLPARAM:cmid@@","bodyend":"</div>","script":"templates.render('filter_poodll/pw-multiplayeraudio',opts).then(function(html, js) {\n\n // The templates object has append, prepend and replace functions.\n templates.appendNodeContents('#' + @@AUTOID@@ + '_container', html, js);\n \n }).fail(function(ex) {\n // Deal with this exception (I recommend core/notify exception function for this).\n\n });","style":"","dataset":"","datasetvars":"","alternate":"","alternateend":""}
{"name":"MultiPlayerAudio-Widget","key":"pw-multiplayeraudio","version":"1.0.3","instructions":"This is an HTML5 audio player that will only play the audio a preconfigured number of times. Insert an audio player or audio link between the tags. If in a quiz, and strict mode is on, it can remember the play position and play count between page reloads.","showatto":"1","showplayers":"0","requirecss":"","requirejs":"","shim":"","defaults":"canplaycount=2,quiz_strict_mode=true|false,quiz_remember_play_position=true|false","amd":"1","body":"<div id='@@AUTOID@@_container'></div>\n<div id=\"@@AUTOID@@_original\" style=\"display: none\">\n@@canplaycount@@ \n@@quiz_strict_mode@@\n@@quiz_remember_play_position@@ \n@@URLPARAM:attempt@@\n@@URLPARAM:cmid@@","bodyend":"</div>","script":"templates.render('filter_poodll/pw-multiplayeraudio',opts).then(function(html, js) {\n\n // The templates object has append, prepend and replace functions.\n templates.appendNodeContents('#' + @@AUTOID@@ + '_container', html, js);\n \n }).fail(function(ex) {\n // Deal with this exception (I recommend core/notify exception function for this).\n\n });","style":"","dataset":"","datasetvars":"","alternate":"","alternateend":""}
19 changes: 1 addition & 18 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3203,23 +3203,6 @@ Flame skin for Poodll standard media recorder
opacity: 0.4 !important;
}

/*
Fixes By Glen
Why are these here? They need to be labelled properly, and with the rest of the template CSS
*/
/*
.poodll_multiplayer{
height: 120px !important;
width: 250px !important;
}
.poodll_multiplayer .meter{
width: 165px !important;
}
.vol-but{
border-radius: 3px !important;
border: none !important;
}
*/

/*
Editor Fixes
Expand Down Expand Up @@ -4559,7 +4542,7 @@ audio.poodll_preview_bmr {
width: 250px;
height: 120px;
text-align: center;
margin-bottom: 100px;
/* margin-bottom: 100px; */
padding: 10px;
background-color: #333;
color: #fff;
Expand Down
79 changes: 62 additions & 17 deletions templates/pw-multiplayeraudio.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<!-- Custom JS from template goes goes here -->
{{#js}}
//<script></script>
require(['jquery','filter_poodll/mediaparser'], function($,parser) {
$('#{{AUTOID}}').data('playtime', {{canplaycount}});
Expand All @@ -33,9 +34,12 @@ var aplayer = $('#' + "{{AUTOID}}").children().first();
var fa = $('#' + "{{AUTOID}}" + ' .fa');
var thestate =$('#' + "{{AUTOID}}" + '_state');
var thetime = $('#' + "{{AUTOID}}" + '_time');
var playtimer = $('#' + "{{AUTOID}}");
var playtimer = $('#' + "{{AUTOID}}");
var lastseconds = 0;
var position_update_interval = 2;
var is_strict_quiz = "{{quiz_strict_mode}}"=="true" && "{{URLPARAM:attempt}}" !="";
var is_remember_pos = is_strict_quiz && "{{quiz_remember_play_position}}"=="true";


var details = parser.parse('{{AUTOID}}_original', 'audio');
aplayer.attr('src',details.mediaurl); // mediaurl, subtitlesurl, sources

Expand All @@ -49,11 +53,17 @@ aplayer.attr('src',details.mediaurl); // mediaurl, subtitlesurl, sources
aplayer[0].volume = 0.2;

//cookies if in strict mode
var cookiename = details.mediaurl + '_' + "{{URLPARAM:attempt}}"+ '_' + "{{URLPARAM:cmid}}";
console.log(cookiename);
console.log(getCookie(cookiename));
if("{{quiz_strict_mode}}"=="true" && "{{URLPARAM:attempt}}" !=""){
var prevplaycount = getCookie(cookiename);
var cookiename_playcount = details.mediaurl + '_pc_' + "{{URLPARAM:attempt}}"+ '_' + "{{URLPARAM:cmid}}";
var cookiename_position = details.mediaurl + '_pos_' + "{{URLPARAM:attempt}}"+ '_' + "{{URLPARAM:cmid}}";

/*
console.log(cookiename_playcount);
console.log(getCookie(cookiename_playcount));
console.log('is_remember_pos',is_remember_pos);
*/

if(is_strict_quiz){
var prevplaycount = getCookie(cookiename_playcount);
if(prevplaycount!==null){
playtimer.data('playtime',prevplaycount);
if(prevplaycount==="0"){
Expand All @@ -62,17 +72,13 @@ aplayer.attr('src',details.mediaurl); // mediaurl, subtitlesurl, sources
}
}





// Append Playtime text
$('#' + "{{AUTOID}}" + '_playtime').empty();
var remainingplays = playtimer.data('playtime');
$('#' + "{{AUTOID}}" + '_playtime').append('Remaining plays: '+remainingplays +'x');



//volume buttons
$('#' + "{{AUTOID}}" + '_vol-up').click(function(){
if(aplayer[0].volume +0.1 > 1){return;}
$('#' + "{{AUTOID}}" + '_indicator').css("width", '+=' + (0.1 * $('.meter').width()));
Expand All @@ -89,8 +95,10 @@ $('#' + "{{AUTOID}}" + '_vol-down').click(function(){
var currentplaycount = playtimer.data('playtime');
currentplaycount--;
//if cookies are enabled set the play count in the cookie
if("{{quiz_strict_mode}}"=="true" && "{{URLPARAM:attempt}}" !="" ){
setCookie(cookiename,currentplaycount,1);
if(is_strict_quiz){
setCookie(cookiename_playcount,currentplaycount,1);
setCookie(cookiename_position,0,1);
lastseconds=0;
}

playtimer.data('playtime',currentplaycount );
Expand Down Expand Up @@ -137,15 +145,41 @@ $('#' + "{{AUTOID}}" + '_vol-down').click(function(){


function play_audio(){
if(is_remember_pos) {
var lastpos = get_last_pos();
if (lastpos > 0) {
aplayer[0].currentTime = lastpos;
}
}
aplayer[0].play();

thestate.text('- playing -');
$(fa).removeClass('fa-play');
$(fa).addClass('fa-circle-o-notch');
$(fa).addClass('fa-spin');
}

function get_last_pos(){
var lastpos = getCookie(cookiename_position);
if(lastpos && lastpos > 0 && $.isNumeric(lastpos)){
return lastpos;
}
return 0;
}


aplayer.bind('durationchange',function(){thetime.text(poodll_mp_fetchtime(aplayer));});
aplayer.bind('durationchange',function(){
if(is_remember_pos) {
var lastpos = get_last_pos();
var currentpos = aplayer[0].currentTime;
if (currentpos < lastpos && currentpos > 0) {
aplayer[0].pause();
aplayer[0].currentTime = lastpos;
aplayer[0].play();
}
}
thetime.text(poodll_mp_fetchtime(aplayer));
});


//time display function
Expand All @@ -155,6 +189,12 @@ function poodll_mp_sec2time(seconds){
date.setSeconds(seconds);
return date.toISOString().substr(11, 8);
}

function poodll_mp_fetchseconds(theplayer){
var a_currenttime= isNaN(theplayer[0].currentTime) ? 0 : theplayer[0].currentTime;
return a_currenttime;
}

function poodll_mp_fetchtime(theplayer){
var a_currenttime= isNaN(theplayer[0].currentTime) ? 0 : theplayer[0].currentTime;
var a_duration= isNaN(theplayer[0].duration) ? 0 : theplayer[0].duration;
Expand All @@ -165,15 +205,20 @@ function poodll_mp_fetchtime(theplayer){
}
//The timer display
aplayer.on('timeupdate',function(e){
if(is_remember_pos) {
var currentseconds = poodll_mp_fetchseconds(aplayer);
if (currentseconds - lastseconds > position_update_interval) {
setCookie(cookiename_position, currentseconds, 1);
lastseconds = currentseconds;
}
}
var displaytime = poodll_mp_fetchtime(aplayer)
thetime.text(displaytime);
});

//show current time
thetime.text(poodll_mp_fetchtime(aplayer));




});
{{/js}}
Loading

0 comments on commit 896f747

Please sign in to comment.