Decrease file size for poor internet connections

Decrease file size for poor internet connections

by Cássio Queiroz -
Number of replies: 6

Hi,

I've been trying to implement a transcode function on mod/assign plugin, this function checks if the file is a video and if it is, transcodes the video to a lower quality and size.
Im using this plugin : https://github.com/jbavari/cordova-plugin-video-editor

My problem is, im unable to find where i should put this function on the code, i want it to run after the file is selected or after the video is recorded. How can i do that ?

I looked all over mm.core.fileuploader's controller and assign's controller but couldn't do it.


Using this version : https://github.com/moodlehq/moodlemobile-phonegapbuild
And this local plugin on serverhttps://moodle.org/plugins/local_mobile

Thank you very much and sorry for the bad english.

Average of ratings: -
In reply to Cássio Queiroz

Re: Decrease file size for poor internet connections

by Eduardo Araujo -

Hello! I'm with the same problem in my application. I doesnot know how and where i can to set the transcode code in moodlemobile.

Any one know how to do this?


In reply to Eduardo Araujo

Re: Decrease file size for poor internet connections

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

Hello,

all the logic to upload the files is inside the fileuploader component (mm.core.fileuploader). Each upload method has its own function:

  • Pictures from album or camera: $mmFileUploaderHelper.uploadImage
  • Recording audio/video: $mmFileUploaderHelper.uploadAudioOrVideo
  • File picker in Android: uploadFileObject inside mmFileUploaderPickerCtrl
  • iOS Shared Files: uploadFileEntry in mmFileUploaderPickerCtrl

In the end all of them use $mmFileUploader#uploadFile to upload the files, but I would recommend applying it to each function instead. The reason is that we support offline usage in assign for new submissions, so if you apply the transcode when the file is picked then you'll decrease the space usage required for offline.

Please let me know if you have any other question or problem.

Cheers,

Dani

Average of ratings: Useful (1)
In reply to Dani Palou

Re: Decrease file size for poor internet connections

by Cássio Queiroz -
Thank you very much Daniel for your answer!

I've tried to apply the transcode function where you pointed me to, but now i am stuck with this problem.
The transcode function requires a path to the file but, the only path i got (at least in the uploadAudioOrVideo Function) has the protocol cdvfile which is incompatible with the transcode.

So i followed how the functions works with that path and came across this block:


  1.   promise = $mmFS.getExternalFile(path).then(function(fileEntry) {
  2.                     return $mmFS.getFileObjectFromFileEntry(fileEntry).then(function(file) {
  3.                             if (file.size > maxSize) {
  4.                                  fileTooLarge = file;
  5.                             }
  6.                         });
  7.                     }).catch(function() {
  8.                     });

Unfortunately when i try to use these functions i got the error "entry.file is not a function".


Any ideas on how i should proceed ?


Thank you very much,

Cássio 


In reply to Cássio Queiroz

Re: Decrease file size for poor internet connections

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 Cássio,

the fileEntry object should have a fullPath attribute. Can you check if the value of that attribute works for you? 

You would have to do something like:

promise = $mmFS.getExternalFile(path).then(function(fileEntry) {
    transclude(fileEntry.fullPath);
});

I guess the fullPath won't include the protocol, so you might have to add "file://" at the start of it to make it work.

Cheers,

Dani

In reply to Dani Palou

Re: Decrease file size for poor internet connections

by Cássio Queiroz -

Hi Daniel, sorry for taking too long to answer you!

First of all, thank you very for your help, took me long enough but i was able to make the transcode work just fine, i'll post how i did it for anyone with similar problem soon.

Unfortunately i stepped into another problem reggarding file size for the upload, the application crashes if the file is bigger than 15mb, looks like this is an old problem: https://moodle.org/mod/forum/discuss.php?d=338239


Do you have any clue on solving it ?

Thanks Again,
Cássio Queiroz

In reply to Cássio Queiroz

Re: Decrease file size for poor internet connections

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 Cássio,

I haven't looked at the size issue for a while, but last time I checked I wasn't able to copy the file. I'll try to take a look at it again.

Kind regards,

Dani