Functions

In this section, you will learn how to use KWIK Player's functions!

play()

Start media playback


                kwikMotion('player').play();
            




pause()

Pause media playback


                kwikMotion('player').pause();
            




paused()

Check if the player is paused


                //Get whether the player is paused or not
                var isPaused = kwikMotion('player').paused();


                //If the player is paused, then play. Else, pause
                if (isPaused)
                kwikMotion('player').play();
                else
                kwikMotion('player').pause();
            




ended()

Returns true if the video has ended, false otherwise.


                //Check ended state
                var endedState = kwikMotion('player').ended();
            




seeking()

Returns true if the player is in the "seeking" state, false otherwise.


                //Get seeking state
                var isInSeeking = kwikMotion('player').seeking();
            




seekable()

Returns the TimeRanges of the media that are currently available for seeking to.


                //Seekable function
                var timeRangeSeekable = kwikMotion('player').seekable();
            




playbackRate()/playbackRate(value)

Gets or Sets the current playback rate. A playbakc of 1.0 repsents normal speed.

The higher value you set, the faster playback you get.

The lower value you set, the slower playback you get.


                //Get current playback rate
                var currentPlaybackRate = kwikMotion('player').playbackRate();

                //Set playback rate to half for instance
                kwikMotion('player').playbackRate(0.5);
            

Parameters

Name Type Required Description
Rate Number Yes New playback rate value to set




duration(seconds)

Get the length in time of the video in seconds


                //Get the duration of the video played
                var lengthOfVideo = kwikMotion('player').duration();
            

Note

The video must have started loading before the duration can be known, and in the case of Flash, may not be known until the video starts playing.


Parameters

Name Type Required Description
seconds Number Yes Duration when setting




currentTime()

Get or set the current time (in seconds)


                //Get currentTime
                var whereYouAt = kwikMotion('player').currentTime();
            

Parameters

Name Type Required Description
seconds Number|String Yes The time to seek to




remainingTime()

Get the time left (in seconds)


                //Get time left
                var timeRemaining = kwikMotion('player').remainingTime();
            




loop()/loop(value)

Get/Set the loop attribute of the video element


                //Get loop value
                var loopValue = kwikMotion('player').loop();

                //Activate loop
                kwikMotion('player').loop(true);

                //Deactivate loop
                kwikMotion('player').loop(false);
            

Parameters

Name Type Required Description
value Boolean Yes True|False to determine whether the video should loop or no




buffered()

Get a TimeRange object with the times of the video that have been downloaded.

If you just want the percent of the video that's been downloaded, use bufferedPercent.


                // Number of different ranges of time have been buffered. Usually 1.
                var numberOfRanges = bufferedTimeRange.length;

                // Time in seconds when the first range starts. Usually 0.
                var firstRangeStart = bufferedTimeRange.start(0);

                // Time in seconds when the first range ends
                var firstRangeEnd = bufferedTimeRange.end(0);

                // Length in seconds of the first time range
                var firstRangeLength = firstRangeEnd - firstRangeStart;
            




bufferedEnd()

Returns the ending time of the last buffered time range.


                //Get ending time
                var endTime = kwikMotion('player').bufferedEnd();
            




bufferedPercent()

Get the percent (as a decimal) of the video that's been downloaded.


                //Get percent
                var percentDownloaded = kwikMotion('player').bufferedPercent();
            




dispose()

Destroys the KWIK motion player and does any necessary cleanup


                kwikMotion('player').dispose();
            




currentType()

Get the current type of the player


                //Get the current type of the player
                var currentType = kwikMotion('player').currentType();
            




error()/error(err)

Set or get the current MediaError


                //Get the current MediaError
                var currentError = kwikMotion('player').error();

                //Set the current MediError
                kwikMotion('player').error(parameter goes here);
            

Parameters

Name Type Required Description
err * Yes A MediaError or a String/Number to be turned into a MediaError




getCache()

Get object for cached values.


                //Get cache
                var cache = kwikMotion('player').getCache();
            




src()/src(source)

Get or Set the source of the video played


                //Get the source
                var vidSource = kwikMotion('player').src();

                //Set the source to a newSource
                kwikMotion('player').src(newSource);
            

Parameters

Name Type Required Description
source String|Object|Array Yes The source URL, object, or array of sources




Volume(percentAsDecimal)

Get or set the current volume of the media


                //This is how to get the current volume:
                var howLoudIsIt = kwikMotion('player').volume();

                //This is how to set the volume:
                kwikMotion('player').volume(0.5); // Set volume to half
            

0 is off (muted), 1.0 is all the way up, 0.5 is half way.


Parameters

Name Type Required Description
percentAsDecimal Number Yes The new volume as a decimal percent




requestFullscreen()

Set the player to be in full screen mode


                //This is how to set the player to be in full screen mode:
                kwikMotion('player').requestFullscreen();
            




exitFullscreen()

Exit the full screen mode


                //This is how to set the player to exit the full screen mode:
                kwikMotion('player').exitFullscreen();
            


controls(bool)

Get or set whether or not the controls are showing.


                //This is how to get whether or not the controls are showing:
                 var controlsShow = kwikMotion('player').controls();

                //This is how to set the controls to be shown:
                kwikMotion('player').controls(true);

                //This is how to set the controls to be hidden:
                kwikMotion('player').controls(false);
            

Parameters

Name Type Required Description
bool Boolean Yes Set controls to showing or not




muted(bool)

Get the current muted state, or turn mute on or off


                //This is how to get whether or not the volume is muted:
                var isVolumeMuted = kwikMotion('player').muted();

                //This is how to set the volume to be muted:
                kwikMotion('player').muted(true);
            

Parameters

Name Type Required Description
muted Boolean No True to mute, false to unmute




aspectRatio(ratio)

Get/Set the aspect ratio of the player


                //Get the aspect ratio of the player
                var playerAspectRatio = kwikMotion('player').aspectRatio();

                //Set the aspect ratio of the player to 16:9
                kwikMotion('player').aspectRatio("16:9");
            

Parameters

Name Type Required Description
ratio String No Defines the aspect ratio of the player




autoPlay()/autoPlay(value)

Get/Set the autoplay attribute


                //Get the current autoplay attribute value
                var currentAutoPlay = kwikMotion('player').autoPlay();

                //Set the autoplay attribute to true
                kwikMotion('player').autoPlay(true);

                //Set the autoplay attribute to flase
                kwikMotion('player').autoPlay(false);
            

Parameters

Name Type Required Description
value Boolean Yes Boolean to determine if the video should autoplay




enterFullWindow()

When fullscreen isn't supported we can stretch the video container to as wide as the browser will let us.


                kwikMotion('player').enterFullWindow();
            


exitFullWindow()

Exit the full window mode


                //This is how to set the player to exit the full screen mode:
                kwikMotion('player').exitFullscreen();
            


currentSrc()

Get the current source of the video played


                //Get the current source
                var vidSource = kwikMotion('player').currentSrc();
            




networkState()

Returns the current state of network activity for the element, from the codes in the list below.

  • NETWORK_EMPTY (numeric value 0) The element has not yet been initialised. All attributes are in their initial states.
  • NETWORK_IDLE (numeric value 1) The element's resource selection algorithm is active and has selected a resource, but it is not actually using the network at this time.
  • NETWORK_LOADING (numeric value 2) The user agent is actively trying to download data.
  • NETWORK_NO_SOURCE (numeric value 3) The element's resource selection algorithm is active, but it has not yet found a resource to use.

                //Get network state
                var netState = kwikMotion('player').networkState();
            




height()/height(value)

Returns/Set the player height.


                //Get height
                var playerHeight = kwikMotion('player').height();

                //Set height
                kwikMotion('player').height(newHeightValue);
            

Parameters

Name Type Required Description
Value Number No Value for new height




width()/width(value)

Returns/Set the player width.


                //Get width
                var playerWidth = kwikMotion('player').width();

                //Set width
                kwikMotion('player').width(newWidthValue);
            

Parameters

Name Type Required Description
Value Number No Value for new width




dimension(dimension)/dimension(dimension, value)

Get/Set dimension of the player.


                //Get dimension(width)
                var playerWidth = kwikMotion('player').dimension('width');

                //Get dimension(height)
                var playerWidth = kwikMotion('player').dimension('height');

                //Set dimension(width)
                kwikMotion('player').dimension('width', newWidthValue);

                //Set dimension(height)
                kwikMotion('player').dimension('height', newWidthValue);
            

Parameters

Name Type Required Description
Dimension String Yes width|height
Value Number No Value of the new dimension (when setting)




load()

Begin loading the src data.


                //Load the src data
                kwikMotion('player').load();
            




poster()/poster(src)

Get/Set the poster image source url.


                //Get the poster image
                var posterImg = kwikMotion('player').poster();

                //Set the poster image
                kwikMotion('player').poster(sourceOfTheNewPoster);
            

Parameters

Name Type Required Description
src String No Poster image source URL

Note

In order to see how the Set Poster button works, click it before start playing the video!




preload()/preload(value)

Get/Set the preload attribute value.


                //Get the preload attribute value
                var preloadValue = kwikMotion('player').preload();

                //Set the preload attribute value
                kwikMotion('player').preload(newpreloadValue);
            

Parameters

Name Type Required Description
value String Yes auto|metadata|none




readyState()

Returns a value that expsses the current state of the element with respect to rendering the current playback position, from the codes in the list below.

  • HAVE_NOTHING (numeric value 0). No information regarding the media resource is available.
  • HAVE_METADATA (numeric value 1). Enough of the resource has been obtained that the duration of the resource is available.
  • HAVE_CURRENT_DATA (numeric value 2). Data for the immediate current playback position is available.
  • HAVE_FUTURE_DATA (numeric value 3). Data for the immediate current playback position is available, as well as enough data for the user agent to advance the current playback position in the direction of playback.
  • HAVE_ENOUGH_DATA (numeric value 4). The user agent estimates that enough data is available for playback to proceed uninterrupted.

                //Check ready state
                var isReady = kwikMotion('player').readyState();
            




supportsFullScreen()

Check if the full screen is supported


                var isFullScSupported = kwikMotion('player').supportsFullScreen();
            




userActive()/userActive(bool)

Get/Set if the user is active


                //Get user active
                var isUserActive = kwikMotion('player').userActive();

                //Set user active
                kwikMotion('player').userActive(newValue);
            

Parameters

Name Type Required Description
bool Boolean Yes New value when setting




videoWidth()

Get video width


                //Get video width
                var videoWidth = kwikMotion('player').videoWidth();
            




videoHeight()

Get video height


                //Get video height
                var videoHeight = kwikMotion('player').videoHeight();
            




tech()

Returns a reference to the current tech.It will only return a reference to the tech if given an object with the IWillNotUseThisInPlugins property on it. This is try and pvent misuse of techs by plugins.


                //Get reference to tech
                var tech = kwikMotion('player').tech();
            




isFullscreen()

Check if the player is in fullscreen mode.


                //Check full screen mode
                var isFullScreen = kwikMotion('player').isFullscreen();
            




fluid(bool)

Add/Remove the fluid class.


                //Add fluid class
                kwikMotion('player').fluid(true);

                //Remove fluid class
                kwikMotion('player').fluid(false);
            

Parameters

Name Type Required Description
bool Boolean Yes True to add fluid, false to remove




addRemoteTextTrack(options)

Add a remote text track.


                //Add remote text track
                kwikMotion('player').addRemoteTextTrack(optionsToAdd);
            

Parameters

Name Type Required Description
options Object Yes Options for remote text track




addTextTrack(kind, label, language)

Add a text track.

In addition to the W3C settings, we allow adding additional info through options.


                //Add a text track
                kwikMotion('player').addRemoteTextTrack(optionsToAdd);
            

Parameters

Name Type Required Description
kind String Yes Captions, subtitles, chapters, descriptions, or metadata
label String No Optional label
options Object Yes Optional language




remoteTextTrackEls()

Get an array of remote html track elements.


                //Get track elements
                var trackEls = kwikMotion('player').remoteTextTrackEls();
            




remoteTextTracks()

Get an array of remote text tracks


                //Get tracks
                var tracks = kwikMotion('player').remoteTextTracks();
            




removeRemoteTextTrack(track)

Remove a remote text track


                //Remove remote text track
                kwikMotion('player').removeRemoteTextTrack(trackObjectToBeRemoved);
            

Parameters

Name Type Required Description
track Object Yes Remote text track to remove


textTracks()

Get an array of associated text tracks.


                //Get text tracks
                kwikMotion('player').textTracks();
            




language(code)

Get the player's language dictionary.


                //Get player language
                var lang = kwikMotion('player').language();
            

Note

The language should be set in the player options if you want the the controls to be built with a specific language. Changing the lanugage later will not update controls text.


Parameters

Name Type Required Description
code String Yes Language to be used



languages()

Get the player language dictionary.


                //Get languages
                var lang = kwikMotion('player').languages();
            




scrubbing()/scrubbing(isScrubbing)

Returns whether or not the user is scrubbing. Scrubbing is when the user has clicked the progress bar handle and is dragging it along the progress bar.


                //Scrubbing
                var isScrubbing = kwikMotion('player').scrubbing();
            

Parameters

Name Type Required Description
isScrubbing Boolean Yes Ture|False