Playing Flash FLV & SWF in MOODLE 2.0

Playing Flash FLV & SWF in MOODLE 2.0

by Andrew McKune -
Number of replies: 6

I am looking at how Moodle 2.0 plays flv movies and swf as i have just created a new installation of moodle 2.0...any ideas?

Average of ratings: -
In reply to Andrew McKune

Re: Playing Flash FLV & SWF in MOODLE 2.0

by Matt Bury -
Picture of Plugin developers

Hi Andrew,

Me too. I'm curious about how Moodle 2.0 apparently makes copies of files every time you create a module instance that references them.

Does this mean that it's better to use a separate file repository, e.g. Amazon S3, for coursewide and sitewide files? (Considering that copying a video file every time you want to reference it could take up a lot of server space).

In reply to Matt Bury

Re: Playing Flash FLV & SWF in MOODLE 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It does not acutally make a separate copy of the file on disc. It just adds a separate reference to the same file on the database.

So, in Moodle 2.0, if two teachers both upload the same huge file without realising that the other teacher is using the same file, Moodle will still only store it once on disc.

In reply to Tim Hunt

Re: Playing Flash FLV & SWF in MOODLE 2.0

by Andrew McKune -

So what is the best viewer for these files, is there one yet?

In reply to Tim Hunt

Re: Playing Flash FLV & SWF in MOODLE 2.0

by Matt Bury -
Picture of Plugin developers

Thanks Tim,

That's good to know. How does Moodle detect whether files are the same? Is it by file name? Size? Metadata?

When I create a new branch for the SWF Activity Module, I'll have to adapt to the new file management system. How would someone reference a moodledata file in an XML file?

In reply to Matt Bury

Re: Playing Flash FLV & SWF in MOODLE 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Moodle uses SHA1 hash of the file contents to recognise identical files, and files are stored on disc with a filename that is that hash. You access files using the file_storage class.

The file identified by its SHA1 hash on disc is then linked to where it us used using the files table. Files in the files table are identified using a combination of things:

(contextid, component, filearea, itemid, filename)

so, as an example, suppose I attached a file called tim.jpg to this forum. contextid would be the context id of this forum. component would be mod_forum - which plugin the file belongs to.

filearea would be 'attachement'. The point is that one forum posts can have files associated with it in two ways. You can add images using the HTML editor, or you can attach files. Moodle needs to distinguish those two types of file that can be associated with a forum post, and filearea name does that.

itemid will be the forum_post id. That distinguishes the particular forum post the file is linked to. If, instead, we were talking about a picture in the forum introduction text, itemid would probably be null, because the contextid uniquely identified which forum.

Finally, filename, because in Moodle 2.0 you can attach several different files to one forum post. That is, the attachments file area is like a folder.

In the database, the link to a file is normally stored using the magic token @@PLUGINFILE@@. Suppose that you put a file tree.jpg in your forum post using the HTML editor. Then in the database, that will be

...<img src="https://moodle.org/pluginfile.php/114/mod_forum/post/716549/tree.jpg" /> ...

When the forum post is output, the code will call the file_rewrite_pluginfile_urls function (in lib/filelib.php). That function takes contextid, component, filearea name, itemid, etc. and replaces that token with a full URL that Moodle can use to find the file ($CFG->wwwroot/pluginfile.php/...).

I don't know how the SWF activity module works, but presumably users upload whatever XML it is, and the SWF file itself, using a Moodle form. In Moodle 2.0 you will use the filepicker form element (like the UI for adding attachments to a forum post here.) That takes care of most of the details for you.

There is documentation at Development:Using_the_file_API.

In reply to Tim Hunt

Re: Playing Flash FLV & SWF in MOODLE 2.0

by Matt Bury -
Picture of Plugin developers

Thanks for taking the time to write this detailed answer to my question. You've saved me a lot of time! smile

This new approach to file management appears to put a hole in my planned SWF Activity Module exchangeable learning interaction content idea. I guess I'll have to find a workaround.

My idea was to have directories, e.g. /example/ that are nested into logical groups such as:

example/mp3/...

example/pix/...

example/video/...

example/xml/...

...all zipped up into example.zip so that it can be shared between Moodle installations. The SWF Activity Module passes the moodledata URL, i.e. http://MOODLE/file.php/course_id/, along with other context specific data, into Flash apps via FlashVars, so that the path to media and data files will always be correct no matter which Moodle installation they're used in. In other words, simple, easy course content sharing -upload the zip file, deploy an instance of the SWF Activity Module, select a Flash app (each app can use the same content directory to create a different type of learning interaction), select a course content directory, e.g. /example/ and link to the corresponding XML file, e.g. example/xml/example_all.xml.

Links in the XML lesson data files, i.e. example_all.xml, look like:

<image>example/pix/my_photo.jpg</image>

<audio>example/mp3/my_audio.mp3</audio>

And in the Flash app, the full URL is constructed, e.g. http://MOODLE/file.php/course_id/ + example/pix/my_photo.jpg

This works well in Moodle 1.9 and it takes literally seconds to deploy a complex, multimedia learning interaction, meaning that you can set up an entire course's worth of interactive multimedia learning interactions in a few minutes. It's also in line with recent research papers I've read into preserving the minimum "granularity" of learning resources and content to facilitate the maximum potential for repurposing and reusing them.

Of course, the new Moodle 2.0 file management system works much better than the old one on in an overall context and respresents a great improvement on the old one.

Any suggestions as to how I could be achieve my aims in Moodle 2.0? Would this be a case of using the file.php legacy script, using a bucket server or something else?

Thanks again for your time.