I'm trying to extend a plugin to support the mobile app. It's a simple use case - I just need to provide a link to a video and track when it has been played (there is more functionality on the desktop version...)
To simplify things I'm pulling the video into the Moodle file system an serving it via a plugin file handler - I've removed all security checks from this and tested using wget so this is definitely all working.
I'm using the core-file directive in my template:
<core-file [file]="{isexternalfile: <% file.isexternalfile %>, fileurl: '<% file.fileurl %>', filename: '<% file.filename %>', timemodified: '<% file.timemodified %>', filesize: '<% file.filesize %>', mimetype: '<% file.mimetype %>'}" component="mod_plugginname" componentId="<% cmid %>"></core-file>There is one function defined in my mobile.php file:
'handlers' => array( // Different places where the plugin will display content.It looks like the function is returning sensible output:
'displayvideo' => array( // Handler unique name (alphanumeric).
'displaydata' => array(
'icon' => $CFG->wwwroot . '/mod/pluginname/pix/icon.gif',
'class' => '',
),
'delegate' => 'CoreCourseModuleDelegate',
'method' => 'mobile_course_view', // Main function in \mod_certificate\output\mobile
'offlinefunctions' => array(
'mobile_course_view' => array(),
)
),
),
'lang' => array( // Language strings that are used in all the handlers.
array('pluginname', 'pluginname')
)
{
"templates": [
{
"id": "main",
"html": "<div>\n <core-course-module-description description=\"Test intro text\" component=\"mod_pluginname\" componentId=\"54\"></core-course-module-description>\n\n <ion-card class=\"card card-md ng-star-inserted\">\n <core-file [file]=\"{isexternalfile: 0, fileurl: 'http://clientnamelynda.projects.test/webservice/pluginfile.php/95/mod_pluginname/videosformobile/1/0_ybjrr47h.mp4', filename: '0_ybjrr47h.mp4', timemodified: '1533645165', filesize: '9837492', mimetype: 'video/mp4'}\" component=\"mod_pluginname\" componentId=\"54\"></core-file>\n </ion-card>\n</div>"
}
],
"javascript": "",
"otherdata": [],
"files": [
{
"filename": "0_ybjrr47h.mp4",
"filepath": "/",
"filesize": 9837492,
"fileurl": "",
"timemodified": 1533645165,
"mimetype": "video/mp4",
"isexternalfile": false
}
],
"restrict": []
}
But there are a few things going wrong:
The files are being ignored when you pre-fetch the module
The file gets displayed when you click on the control but isn't being downloaded correctly, a 2 byte file gets written instead. If I use an external URL it does work occasionally and loads the full 10MB file but if you close and reopen the activity it overwrites it with a 2 byte file again.
I've got a feeling I've missed something simple... but I cannot get core-file or any of the related directives to work consistently.