Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Mediacapture plugin recorders: Difference between revisions

From MoodleDocs
m (Text replacement - "<code php>" to "<syntaxhighlight lang="php">")
 
(7 intermediate revisions by 2 users not shown)
Line 15: Line 15:


== Example ==
== Example ==
Following recorders are examples of recorders used by mediacapture repository plugin for demonstration of recording within Moodle. They are not developed by me. I am grateful to the authors for their support in allowing me to use these recorders within mediacapture.
Following recorders are examples of recorders used by mediacapture repository plugin for demonstration of recording within Moodle. I am grateful to the authors for their support in allowing me to use these recorders within mediacapture.


*[https://github.com/ankitdbst/moodle-repository_mediacapture/tree/master/recorders/nanogong Nanogong Recorder]
*[https://github.com/ankitdbst/moodle-repository_mediacapture/tree/master/recorders/nanogong Nanogong Recorder]
Line 28: Line 28:
# Create the following files and add them to the ''myrecorder'' folder:
# Create the following files and add them to the ''myrecorder'' folder:
#* ''lib.php'', the main class will be named "repository_mediacapture_myrecorder"
#* ''lib.php'', the main class will be named "repository_mediacapture_myrecorder"
# Create the language file ''repository_mediacapture_myrecorder.php'' and add it to the plugin folder, keeping the following folder structure:
# Add the language strings used by the recorders to the mediacapture/lang/ dir.
#*''moodle/repository/mediacapture/myrecorder/lang/en/repository_mediacapture_myrecorder.php''
# Create module.js and styles.css (optional)
# Create module.js and styles.css (optional)


Line 42: Line 41:


For example:
For example:
<code php>
<syntaxhighlight lang="php">
public static function get_type_option_names() {
public static function get_type_option_names() {
     array('myrecorder', 'config');
     array('myrecorder', 'config');
}
}
</code>
</syntaxhighlight>


====add_config_form($mform)====
====add_config_form($mform)====
Line 52: Line 51:


For example, to display the standard repository mediacapture plugin settings along with the custom ones for the recorders use:
For example, to display the standard repository mediacapture plugin settings along with the custom ones for the recorders use:
<code php>
<syntaxhighlight lang="php">
public function add_config_form($mform) {
public function add_config_form($mform) {
     $mform->addElement('advcheckbox', 'myrecorder', get_string('nanogong', 'repository_mediacapture'),
     $mform->addElement('advcheckbox', 'myrecorder', get_string('nanogong', 'repository_mediacapture'),
                         null, array('group' => 1));
                         null, array('group' => 1));
}
}
</code>
</syntaxhighlight>


==Mediacapture recorder APIs==
==Mediacapture recorder APIs==
Line 70: Line 69:


With the example above, this function may look like:
With the example above, this function may look like:
<code php>
<syntaxhighlight lang="php">
public function view($mform, $options) {
public function view($mform, $options) {
     $recorderhtml = '<object></object>';
     $recorderhtml = '<object></object>';
Line 79: Line 78:
     $mform->addElement('submit', 'save', get_string('save', 'repository_mediacapture'));
     $mform->addElement('submit', 'save', get_string('save', 'repository_mediacapture'));
}
}
</code>
</syntaxhighlight>


====post_url()====
====post_url()====
Use this function when you need to post the recorded data to a file where it can be moved to a temp location in moodle (data root).
Use this function when you need to post the recorded data (via ajax) to a file where it can be moved to a temp location in moodle (data root).


<code php>
<syntaxhighlight lang="php">
public function post_url() {
public function post_url() {
     global $CFG;
     global $CFG;
     return new moodle_url("$CFG->wwwroot/repository/mediacapture/recorders/myrecorder/record.php");
     return new moodle_url("$CFG->wwwroot/repository/mediacapture/recorders/myrecorder/record.php");
}
}
</code>
</syntaxhighlight>


====string_keys()====
====string_keys()====
You may list the strings used by your plugin here.
You may list the strings used by your plugin here.


<code php>
<syntaxhighlight lang="php">
public function string_keys() {
public function string_keys() {
   return array('appletnotfound', 'norecordingfound', 'nonamefound');
   return array('appletnotfound', 'norecordingfound', 'nonamefound');
}
}
</code>
</syntaxhighlight>


====min_version()====
====min_version()====
Line 104: Line 103:
supported by the recorder.
supported by the recorder.


<code php>
<syntaxhighlight lang="php">
public function min_version() {
public function min_version() {
   return array('java' => 1.5, 'flash' => 11);
   return array('java' => 1.5, 'flash' => 11);
}
}
</code>
</syntaxhighlight>


====supported_media()====
====supported_media()====
This function will return list of media supported by the recorder.
This function will return list of media supported by the recorder.


<code php>
<syntaxhighlight lang="php">
public function supported_media() {
public function supported_media() {
     return array('audio', 'video');
     return array('audio', 'video');
}
}
</code>
</syntaxhighlight>


====supported_types()====
====supported_mediatypes()====
This function will return list of technologies used by the recorder.
This function will return list of technologies used by the recorder.


<code php>
<syntaxhighlight lang="php">
public function supported_types() {
public function supported_mediatypes() {
     return array('java', 'flash', 'html5');
     return array('java', 'flash', 'html5');
}
}
</code>
</syntaxhighlight>
 
====supported_filetype()====
This function will return string of supported filetype associated with the recording.
 
<syntaxhighlight lang="php">
public function supported_filetype() {
    return '.wmv';
}
</syntaxhighlight>


===Functions you *MAY* override===
===Functions you *MAY* override===


====temp_dir()====
====temp_dir()====
This function returns the temp directory where recorders should upload their files.
This function returns the temp directory where recorders should upload their temp files.


<code php>
<syntaxhighlight lang="php">
public function temp_dir() {
public function temp_dir() {
     global $USER;
     global $USER;
     return make_temp_directory('repository/mediacapture/' . $USER->id);
     return make_temp_directory('repository/mediacapture/' . $USER->id);
}
}
</code>
</syntaxhighlight>


==See also==
==See also==

Latest revision as of 13:33, 14 July 2021

Introduction

Mediacapture is a repository plugin framework which allows recorders to record and upload audio/video content to Moodle easily.

Overview

The 3 different parts to write

  1. Administration - You can customise the way administrators and users can configure their recorders.
  2. Recorder display - You can also customize the view of the recorders.
  3. I18n - Internationalization should be done at the same time as you're writing the other parts.

History

Mediacapture plugin exists from Moodle 2.3

Example

Following recorders are examples of recorders used by mediacapture repository plugin for demonstration of recording within Moodle. I am grateful to the authors for their support in allowing me to use these recorders within mediacapture.

Template

There is a template available in [1]

File structure

  1. Create a folder for your recorder in moodle/repository/mediacapture/recorders e.g. moodle/repository/mediacapture/recorders/myrecorder
  2. Create the following files and add them to the myrecorder folder:
    • lib.php, the main class will be named "repository_mediacapture_myrecorder"
  3. Add the language strings used by the recorders to the mediacapture/lang/ dir.
  4. Create module.js and styles.css (optional)

Administration APIs

Functions you *MUST* override

get_type_option_names

This function must be declared static
Return an array of string. These strings are setting names. These settings are shared by all instances.

For example:

public static function get_type_option_names() {
    array('myrecorder', 'config');
}

add_config_form($mform)

This is for modifying the Moodle form displaying the recorder settings.

For example, to display the standard repository mediacapture plugin settings along with the custom ones for the recorders use:

public function add_config_form($mform) {
    $mform->addElement('advcheckbox', 'myrecorder', get_string('nanogong', 'repository_mediacapture'),
                        null, array('group' => 1));
}

Mediacapture recorder APIs

Functions you *MUST* override

view($mform, $options)

Use this function to display the view of the recorder using the $mform (moodle form). The object code for recorders can be embedded by using the 'html' tag for $mform. The form elements *must* contain the required paramters by mediacapture plugin viz filename, filepath and filetype.

With the example above, this function may look like:

public function view($mform, $options) {
    $recorderhtml = '<object></object>';
    $mform->addElement('html', $recorderhtml);
    $mform->addElement('hidden', 'filepath', '');
    $mform->addElement('hidden', 'filetype', 'xyz');
    $mform->addElement('text', 'filename', get_string('name', 'repository_mediacapture'));
    $mform->addElement('submit', 'save', get_string('save', 'repository_mediacapture'));
}

post_url()

Use this function when you need to post the recorded data (via ajax) to a file where it can be moved to a temp location in moodle (data root).

public function post_url() {
    global $CFG;
    return new moodle_url("$CFG->wwwroot/repository/mediacapture/recorders/myrecorder/record.php");
}

string_keys()

You may list the strings used by your plugin here.

public function string_keys() {
   return array('appletnotfound', 'norecordingfound', 'nonamefound');
}

min_version()

This function will return an array structure listing the min version of various media supported by the recorder.

public function min_version() {
   return array('java' => 1.5, 'flash' => 11);
}

supported_media()

This function will return list of media supported by the recorder.

public function supported_media() {
    return array('audio', 'video');
}

supported_mediatypes()

This function will return list of technologies used by the recorder.

public function supported_mediatypes() {
    return array('java', 'flash', 'html5');
}

supported_filetype()

This function will return string of supported filetype associated with the recording.

public function supported_filetype() {
    return '.wmv';
}

Functions you *MAY* override

temp_dir()

This function returns the temp directory where recorders should upload their temp files.

public function temp_dir() {
    global $USER;
    return make_temp_directory('repository/mediacapture/' . $USER->id);
}

See also