bags/MediaBagElement. MediaBagElement

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, file, zipopt)

MediaBagElement constructor

Parameters:
NameTypeAttributesDescription
basePathstring

Path to be used as a prefix of the file name

filestring

The media file name

zipexternal:JSZip<optional>

An optional JSZip object from which the file must be extracted.

Members

animated :boolean

Flag used for animated GIFs

Type:
  • boolean

basePath :string

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

Type:
  • string

data :object

When loaded, this field will store the realized media object

Type:
  • object

ext :string

Normalized extension of file, useful to guess the media type

Type:
  • string

file :string

The name of the file where this element is stored

Type:
  • string

fontName :string

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

Type:
  • string

name :string

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

Type:
  • string

ready :boolean

Flag indicating that data is ready to be used

Type:
  • boolean

timeout :number

Time set to load the resource before leaving

Type:
  • number

type :string

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

Type:
  • string

zip :external:JSZip

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

Methods

_onReady()

Notify listeners that the resource is ready

build(callback, ps, force, level)

Instantiates the media content

Parameters:
NameTypeDefaultDescription
callbackfunction

Callback method called when the referred resource is ready

psmodule:JClicPlayer.JClicPlayernull

An optional PlayStation (currently a JClicPlayer) used to dynamically load fonts

forcebooleanfalse

Used only in media of type 'audio'. When true, a static audioPlayer element will be loaded with this media source

levelnumber1

Priority level of the media content to be built. Used only n audio elements.

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

checkReady() → {boolean}

Checks if this media element is ready to start

Returns:
  • true if ready, false otherwise
Type: 
boolean

checkTimeout() → {boolean}

Checks if this resource has timed out.

Returns:
  • true if the resource has exhausted the allowed time to load, false otherwise
Type: 
boolean

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:
  • The resulting object, with minimal attrributes
Type: 
object

getFileType(ext) → {string}

Determines the type of a file from its extension

Parameters:
NameTypeDescription
extstring

The file name extension

Returns:
Type: 
string

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:
Type: 
string

getFullPathPromise() → {external:Promise}

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

Returns:
Type: 
external:Promise

isEmpty() → {boolean}

Checks if the MediaBagElement has been initiated

Returns:
Type: 
boolean

setAttributes(data)

Loads the element properties from a data object

Parameters:
NameTypeDescription
dataobject

The data object to parse

setProperties($xml)

Loads this object settings from a specific JQuery XML element

Parameters:
NameTypeDescription
$xmlexternal:jQuery

The XML element to parse

(static) getAudioPlayer(level) → {external:HTMLAudioElement}

Gets the static HTMLAudioElement
associated to the requested priority level.

Parameters:
NameTypeDefaultDescription
levelnumber1

The priority level

(static) resetAudioElements()

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