Namespace: media

media

Audio and video functions.

Source:

Members

defaults

Default options for the media player

Source:

Methods

image(file, options) → {String}

Creates an img tag.

Parameters:
Name Type Argument Description
file String

The filename of the image. If no path is specified, vorple.media.defaults.imagePath will be used.

options Object <optional>

Additional attributes added to the image.

Source:
Returns:

The HTML code for the img tag.

Type
String
Example
 
vorple.media.image( 'foo.jpg', { class: 'bar' } )
    == <img src="media/image/foo.jpg" class="bar">
    

isMuted(types) → {boolean|Array.<boolean>}

Check whether a media type is muted and return the current status.

Parameters:
Name Type Description
types string | Array.<string>

The audio type (music, sound, or all) as a single string or an array.

Source:
Returns:

true if media type is muted, false otherwise. An array of truth values is returned if the parameter was given as an array.

Type
boolean | Array.<boolean>

mute(types, options)

Mutes or unmutes all given types of media. Muting affects also future instances of the given media. Note that muting doesn't stop loading the media files, they are just played without sound.

Parameters:
Name Type Description
types Object

The types of media to affect and the mute status of those objects as boolean (true: mute, false: unmute).

options Object

Options if default containers must be overridden.

Source:
Example
 Mute music and unmute sound: 
  vorple.media.mute({ music: true, sound: false });

muteAll(state) → {Boolean}

Mutes or unmutes all media types.

Parameters:
Name Type Argument Default Description
state Boolean <optional>
true

True to mute or false to unmute all.

Source:
Returns:

The new state of global mute (true: all muted, false: all unmuted).

Type
Boolean

playMusic(file, options) → {string}

Play a music file.

This is otherwise functionally identical to vorple.media.playSound(), with two key differences:

  • Any previously playing music (if any) fades out before the new starts

  • Music loops automatically unless otherwise instructed.

Parameters:
Name Type Argument Description
file string

Music file to be played

options object <optional>

Any SoundManager's createSound() options, plus these: - loop: set to false to not have the music loop again after playing - fadeSpeed: how fast the old music should fade out before starting the new one. Set to 100 for no fade. See media#stopMusic for details.

Source:
See:
  • vorple.media.playSound
Returns:

The audio player's id.

Type
string

playSound(file, options) → {string}

Play an audio file.

If SoundManager has not finished initializing yet, the sound file waits for it to happen before it starts. The function returns its id even if it hasn't been passed to SoundManager yet.

If Undum is replaying a saved story, Vorple will not play the sound. Even in that case the (hypothetical) id is returned.

The volume will be set to 0 if sounds have been muted.

Parameters:
Name Type Argument Description
file string

The sound file to be played.

options object <optional>

Any SoundManager's createSound() options, plus these:
- loop: set to true to have the sound repeat (indefinitely) after playing.
- destructAfter: set to false to have SoundManager not destroy the player instance after the sound has finished playing.

Source:
See:
Returns:

The audio player's id.

Type
string

preloadImage(files, options) → {Image|Array.<Image>}

Preload image files.

Parameters:
Name Type Argument Description
files string | Array.<string>

Filename of the image to load, or an array of files to load.

options Object <optional>
nametypedefaultdescription
imagePathstring'media/image' The default path for the images.
Source:
Returns:

The Image object of the preloaded images, or an array of Image objects if multiple image files were given.

Type
Image | Array.<Image>

stopAll(fadeSpeed)

Stop all music and sound effects. This is shorthand for calling both {@see media#stopMusic} and {@see media#stopSounds}.

There is no callback for when all sound has stopped. If one is needed it's easiest to call {@see media#stopMusic} and {@see media#stopSounds} separately with the callback attached to either one of them.

Parameters:
Name Type Argument Default Description
fadeSpeed number <optional>
5

The speed in which sounds fade out, larger is faster. Use 100 to stop sounds immediately.

Source:

stopMusic(fadeSpeed, callback)

Stop the currently playing music.

Parameters:
Name Type Argument Default Description
fadeSpeed integer <optional>
5

The speed in which the music fades out, larger is faster. Use 100 to stop the sound immediately. The number tells how much the volume is decreased every 50 milliseconds. For example using the default volume 80 and the default fade out speed 5, it takes 80 / 5 * 50 = 800 milliseconds = 0.8 seconds for the sound to fade out.

callback function <optional>

A callback function to execute when the music has actually stopped (i.e. has faded out completely).

Source:

stopSound(id, fadeSpeed, callback)

Stop a single audio file.

Parameters:
Name Type Argument Default Description
id string

The id of the audio to stop

fadeSpeed integer <optional>
100

Fade out speed. See stopMusic().

callback function <optional>

A callback function to execute when the sound has actually stopped (i.e. has faded out completely).

Source:

stopSounds(fadeSpeed, callback)

Stop all currently playing sound effects.

Parameters:
Name Type Argument Default Description
fadeSpeed integer <optional>
100

Fade out speed. See stopMusic().

callback function <optional>

A callback function to execute when all sounds have actually stopped (i.e. faded out completely). Callback is called immediately if there are no sounds active.

Source:

toggleMute(types) → {boolean|Array.<boolean>}

Toggle mute status of given media types.

Parameters:
Name Type Description
types string | Array

The media type to toggle, or an array of media types to toggle.

Source:
Returns:

If a string was given as the parameter, the new mute status is returned as a boolean (true: muted, false: unmuted). If an array is given, an array is returned with the corresponding mute statuses.

Type
boolean | Array.<boolean>

youtube(id, options) → {string}

YouTube video embedding.

Parameters:
Name Type Argument Description
id string

The id of the video to embed (the xxx part of youtube.com/watch?v=xxx)

options object <optional>

heightHeight of the player
widthWidth of the player
parametersYouTube player parameters (see http://code.google.com/apis/youtube/player_parameters.html)
Any HTML attributes are allowed and they're applied to the generated <object> tag.

Source:
See:
Returns:

Embedding HTML code

Type
string
Vorple Copyright © 2011-2014 the Vorple project
Documentation generated by JSDoc 3.2.2 on Wed May 07 2014 14:47:40 GMT+0300 (EEST) using the DocStrap template.