MediaBagElement

Source: MediaBagElement.js:45

This kind of objects are the components of MediaBag.

Media elements have a name, a reference to a file (the file field) and, when initialized,
a data field pointing to a object containing the real media. They have also a flag indicating
if the data must be saved on the JClicProject zip file or just maintained as a reference
to an external file.


Constructor

new MediaBagElement( basePath: string, file: string, zip?: external:JSZip, ): MediaBagElement

MediaBagElement constructor

Parameters

  • basePath (string) — Path to be used as a prefix of the file name
  • file (string) — The media file name
  • zip (external:JSZip, optional) — An optional JSZip object from which the file must be extracted.

Instance Methods

setProperties($xml: external:jQuery)

Loads this object settings from a specific JQuery XML element

Parameters

getAttributes(): object

Gets a object with the basic attributes needed to rebuild this instance excluding functions,
parent references, constants and also attributes retaining the default value.
The resulting object is commonly usued to serialize elements in JSON format.

Returns

  • object

setAttributes(data: object)

Loads the element properties from a data object

Parameters

  • data (object) — The data object to parse

checkAnimatedGif()

Checks if the image associated with this MediaBagElement is an animated GIF

Based on: https://gist.github.com/marckubischta/261ad8427a214022890b
Thanks to @lakenen and @marckubischta

isEmpty(): boolean

Checks if the MediaBagElement has been initiated

Returns

  • boolean

getFileType(ext: string): string

Determines the type of a file from its extension

Parameters

  • ext (string) — The file name extension

Returns

  • string

build( callback: function, ps: module:JClicPlayer.JClicPlayer, force: boolean, level: number, )

Instantiates the media content

Parameters

  • callback (function) — Callback method called when the referred resource is ready
  • ps (module:JClicPlayer.JClicPlayer, default: null) — An optional PlayStation (currently a JClicPlayer) used to dynamically load fonts
  • force (boolean, default: false) — Used only in media of type 'audio'. When true, a static audioPlayer element will be loaded with this media source
  • level (number, default: 1) — Priority level of the media content to be built. Used only n audio elements.

checkReady(): boolean

Checks if this media element is ready to start

Returns

  • boolean

checkTimeout(): boolean

Checks if this resource has timed out.

Returns

  • boolean

_onReady()

Notify listeners that the resource is ready

getFullPath(): string

Gets the full path of the file associated to this element.
WARNING: This function should be called only after a successful call to getFullPathPromise

Returns

  • string

getFullPathPromise(): external:Promise

Gets a promise with the full path of the file associated to this element.

Returns

Static Methods

getAudioPlayer(level: number): external:HTMLAudioElement

Gets the static HTMLAudioElement
associated to the requested priority level.

Parameters

  • level (number, default: 1) — The priority level

Returns

resetAudioElements()

Clear all references to audio players and audio elements
To be called when a new activity starts

Instance Fields

name: string

The name of this element. Usually is the same as file

file: string

The name of the file where this element is stored

fontName: string

The font family name, used only in elements of type 'font'

basePath: string

The path to be used as base to access this media element

zip: external:JSZip

An optional JSZip object that can act as a container of this media

data: object

When loaded, this field will store the realized media object

ready: boolean

Flag indicating that data is ready to be used

ext: string

Normalized extension of file, useful to guess the media type

type: string

The resource type ('audio', 'image', 'midi', 'video', 'font')

timeout: number

Time set to load the resource before leaving

animated: boolean

Flag used for animated GIFs