Struggling to get core-file to work

Struggling to get core-file to work

by Andrew Hancox -
Number of replies: 2
Picture of Core developers Picture of Plugin developers

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.
'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')
)
It looks like the function is returning sensible output:

{
"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.

Average of ratings: -
In reply to Andrew Hancox

Re: Struggling to get core-file to work

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Andrew,

looking at your code and the output I think you aren't doing anything wrong, but there are a couple of bugs in the app that are affecting this.

The first one is a bug that affects prefetching the activity, it's this one:

https://tracker.moodle.org/browse/MOBILE-2531

You should be able to prefetch your activity once this issue is integrated.

The other one is also a known issue, but this one is trickier. Here's its tracker issue:

https://tracker.moodle.org/browse/MOBILE-2476

If you look at the comments I explain what's causing the 2 bytes problem, it's the WebView cache. We still haven't decided how to fix the issue in the app, but as a workaround you might want to add a hash to the embedded video URL so it's different than the download URL.

Cheers,

Dani

In reply to Dani Palou

Re: Struggling to get core-file to work

by Andrew Hancox -
Picture of Core developers Picture of Plugin developers

That's a massive relief - I thought I was losing my mind! I had already spotted the first issue but hadn't see 2476. I'll try your work around.

Thanks for your reply.