Quiz with programmable mp3 audio in secure window.

Quiz with programmable mp3 audio in secure window.

by Gyorgy Szentgyorgyi -
Number of replies: 7

Hi everybody,
I don't know if it is the right place for what I want to say but we'll see.
I run a couple of copies of Moodle for various companies and one client came up with the request to use the quiz activity for testing language skills including listening comprehension. The point is that they want to use the secure quiz window with a programmable mp3 player that enables them to control how many times an audio files can be played during a quiz session.
I looked up the Moodle site for some ideas but it was not too much help so I've programmed my own hack to satisfy them.

How it works:
when the question with the audio is edited and the link to the mp3 file has been made change the editor into HTML mode. Look for the
<a href="....myaudiofile.mp3">link here </a> remove the link ("link here") and simply write the number of the required replays behind the .mp3 like this : <a href="....myaudiofile.mp32"></a>.
In this case the player will play the file twice. The integer behind the mp3 can be anything between 1 and 9.

------------------------------------------------------

The required modifications:

  1. to modify the mp3 player so that it can accept control values
  2. to modify the mp3 filter to send the control value to the mp3 player
  3. to remove the "Save without submitting " button from the bottom of the quiz in secure mode
  4. to disable the F function buttons and the Ctrl+N és Ctrl+R combinations while in secure mode

Used Moodle version: 1.9
Tested on IE 7 and Firefox 3. (Not a thorough test but it worked so far.)

STEP 1.
Used file : \moodle\filter\mediaplugin\mp3player.fla
New variable: playnr (integer 1...9) The audio file can be played "playnr" times.
Code:


if (playnr>0) {
playnr = playnr - 1
if (playnr<0) {
playnr=0
}
if (playnr==0) {
playBtn.enabled = false;
}
pauseBtn.enabled = false;
slider.handle.enabled=false;
}

Effect: The Pause button and the Slider are disabled at the first Play buton press and when the number of replays reaches "playnr" the Play button is also disabled.

STEP 2.
Used file: \moodle\filter\mediaplugin\filter.php
New variable
: playnr
Code:
1. Modified regexp for the mp3 filter (separating the playnr from the end of the mp3 extension):

if ($CFG->filter_mediaplugin_enable_swf) {
$search = '/<a.*?href="([^<]+\.swf)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_swf_callback', $newtext);

2. Modified var FO = for the mp3 filter (playnr is sent to the player)

var FO = { movie:"'.$CFG->wwwroot.'/filter/mediaplugin/mp3player.swf?src='.$url.'",
width:"90", height:"15", majorversion:"6", build:"40", flashvars:"'.$c.'&playnr='.$link[3].'", quality: "high"};

STEP 3.
Used file: \moodle\mod\quiz\attempt.php
Code:
1. In the Print the submit buttons section:

if (!$quiz->popup) {
echo "<input type=\"submit\" name=\"saveattempt\" value=\"".get_string("savenosubmit", "quiz")."\" />\n";
}

Effect: The "Save without submitting " is not printed if the secure window option is selected during the quiz setting

STEP 4.
Used file:
\moodle\mod\quiz\protect_js.php
Code:

//Source website:
//http://www.gklein.org/tests/js/disablekey.js
//http://www.gklein.org/tests/js/disablekey.html
//http://www.gklein.org

setEventListener(disableKey);

function setEventListener(eventListener) {
if (document.addEventListener) document.addEventListener('keypress', eventListener, true);
if (!document.getElementById) return;
}

function disableKey(event) {
if (!event) event = window.event;
if (!event) return;
var keyCode = event.keyCode ? event.keyCode : event.charCode;
// keyCode for F% on Opera is 57349 ?!
if (keyCode >= 110 && keyCode <= 123) {
// Standard DOM (Mozilla):
if (event.preventDefault) event.preventDefault();
return false;
}
}I

//Source website
//http://forums.devarticles.com/javascript-development-22/disable-new-window-opening-7531.html

document.Xonkeydown= function(){
if ((((event.keyCode == 78)||(event.keyCode == 82)) && (event.ctrlKey)) || (((event.keyCode >= 110)&&(event.keyCode <= 123)))){
event.cancelBubble = true;
event.returnValue = false;
event.keyCode = false;
return false;
}
}

Effect: when in secure window the F function buttons and the Ctrl+N és Ctrl+R combinations are disabled.

Notes:

  • although I program desktop applications routinely I don't have any experience in web programming. I fully understand Step1-3 but the 4. one is a mess for me. I looked up some code snipets on the net, modified them so I have to admit it is not a piece of diamond but it works)
    I would be very happy if somebody could clean up this last code segment.
  • Of course the secure window is not secure enough but it is a little bit better than the original one.
  • I think the keyboard should be restricted for examinations on the OS level. It can be done easyly with a key mapper before launching the browser for the exam. I tried a very simple one, found it in five minutes.(Key Remapper 1.03 http://www.softarium.com/) Everything can be disabled in a second including the Window keys, Alt+Tab ... using a GUI.


Average of ratings: Useful (1)
In reply to Gyorgy Szentgyorgyi

Re: Quiz with programmable mp3 audio in secure window.

by Michael Bonney -
I would abandon that and integrate a Flash object in a secure window that implements an audio track counter.
In reply to Gyorgy Szentgyorgyi

Re: Quiz with programmable mp3 audio in secure window.

by Libby Ferguson -
This is exactly what I'm looking for.
It works great! Thanks a lot for sharing.
I love this moodle community smile
In reply to Gyorgy Szentgyorgyi

Re: Quiz with programmable mp3 audio in secure window.

by Jason Hollowell -
Gyorgy,

Thanks so much for this post! I'm very excited to give this a try but I have one BIG problem. I don't know how to edit an flv file.... sad

I have Adobe Flash CS4 but when I open the flv file with it, I don't see anywhere where I can enter code (ActionScript). I'm at a loss without that ability.

Additionally, I'm using the much nicer looking swf player that was introduced here from 1pixelout and I only have the swf file and not the flv so I'm not sure if I can even access the code in an swf file.

I'm pretty much feeling around in the dark when it comes to Flash sad

Jason
In reply to Jason Hollowell

Re: Quiz with programmable mp3 audio in secure window.

by Bob Phan -

Hi,

I also have a problem with being able to edit the .flv file. I was previously able to edit it before but after upgrading to Moodle 2.0, I'm unable to edit it.

 

Is there another way to have a programmable mp3 audio player?  I am looking for something that allows the student to just play it only once.

Thanks,

Bobby

In reply to Gyorgy Szentgyorgyi

Re: Quiz with programmable mp3 audio in secure window.

by Jason Hollowell -

Gyorgy,

I've been working with this and am very happy with what it allows us to do but I have one question about the variables that can be passed to the mp3 player.

I want to pass  WaitForPlay=no but it seems that it doesnt't work. The audio will not begin playing until it has completely loaded. Is there any way around this? I'd like to allow users to begin listening to audio even though it hasn't been completely loaded.

Jason

In reply to Jason Hollowell

Re: Quiz with programmable mp3 audio in secure window.

by Matt Bury -
Picture of Plugin developers

Hi guys,

You'll probably be interested in a project I started a while ago. It's an MP3 player for tests that's programmable via FlashVars so that you can set a variety of options: http://code.google.com/p/moodle-mp3-player-for-tests/ It's already used in the new version of the Hot Potatoes activity module for Moodle 2.0.

One of you mentioned some kind of playback counter. That could easily be incorporated either:

#1 In users' browser caches (simplest but least secure) using a local shared object (Flash cookie) or...

#2 In a database table (most secure) that keeps track of who, when and how many times a user has accessed a particular MP3 file. This would also require a Flash Remoting gateway to facilitate fast, light, efficient communication between Flash and Moodle. I've already modified one for Moodle for the SWF Activity Module here: http://code.google.com/p/swf-activity-module/

This is perhaps where you could help me. If you could create a new Moodle filter that embeds the MP3 Player for tests (see current parameters here: http://code.google.com/p/moodle-mp3-player-for-tests/wiki/HowToUse) I could create the Flash gateway and modify the MP3 Player appropriately.

How does this sound?

Looking forward to your replies,

Matt

In reply to Matt Bury

Re: Quiz with programmable mp3 audio in secure window.

by Jason Hollowell -

Matt,

Wow, it's been almost a year since this post and I'm just now stumbling onto it. Sorry for a VERY long delay in replying. shy

You have probably moved on from this but just to respond, I'm afraid that I don't have the skill to create a new filter. I'd love to if I could though.

I got back to this thread because I'm looking to accomplish what I did in 1.9 (mp3 player with no controls and control over the number of times a file plays) in 2.1 but haven't had any success.

If you have any ideas or suggestions they will be much appreciated.

Jason