Installation
NPM
npm install gsvideoframe --save
Yarn
yarn add gsvideoframe --save
Usage
Include jQuery:
<script type="text/javascript" src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
Include gsVideoFrame:
<script type="text/javascript" src="./dist/scripts/gsVideoFrame.min.js"></script>
Optionally include default skin:
<link rel="stylesheet" src="./dist/styles/default.css">
Options
- src (string)
- The
src attribute is the URL to view the video.
- The script will parse YouTube and Vimeo URL's and will create an iFrame embed from them.
- Note: YouTube URL's with .com and .be are currently supported.
- autoplay (number) [Default
1]
- This parameter determines whether or not the video automatically plays once it is opened
- params (object)
- query (object) [Default
{}]
- Object that defines the query string parameters to be appended to the embedded iFrame
- api (object) [Default
{}]
- Object that defines the parameters to be passed to the video provider's API constructor
- target (string | jQuery object) [Default
false]
- The target where the video should be embedded.
- This can be a selector string (ex:
"#gsVideoFrame")
- Or this can be a jQuery object (ex:
$('#gsVideoFrame')).
- In the default case
false or if the target cannot be found, the video will be appended to the body element.
- esc (boolean) [Default
true]
- Determines whether to add an event observer to listen for the escape key to close the video.
- time (object)
- Object that defines animation timing
- fadeIn [Default
250] - Time for video fade-in animation
- fadeOut [Default
250] - Time for video fade-out animation
- class (object)
- Object that defines HTML classes used throughout the script
- opening [Default
gsvideoframe-opening] - Class applied to content as it is opening
- closing [Default
gsvideoframe-closing] - Class applied to content as it is closing
- iframe [Default
gsvideoframe-frame] - Class applied to embedded iFrame
- id (string)
- Unique HTML ID given to the embedded iFrame
- This defaults to "video" plus a timestamp
- container (string [Default
div]
- HTML / Element to be used as the frame container. Use
false to prevent the script from wrapping your content in a container
- closeButton (string | jQuery object)
- HTML / Element to be used as the close button. Use
false to remove the close button
Example:
$('#element').gsVideoFrame({
params: {
api: {
color: 'white'
}
},
class: {
iframe: 'video-player'
},
src: 'https://www.youtube.com/watch?v=Rk6_hdRtJOE',
autoplay: 1
});
Events
- gsvf:apiloaded (function)
- Event called when the player API is loaded
- gsvf:beforeopen (function)
- Event called before the video is embedded
- gsvf:open (function)
- Event called after the video is embedded
- gsvf:play (function)
- Event called when the video is played
- gsvf:pause (function)
- Event called when the video is paused
- gsvf:ended (function)
- Event called when the video has finished playing
- gsvf:ready (function)
- Event called when the video is ready
- gsvf:error (function)
- Event called when an error has occurred
- gsvf:beforeclose (function)
- Event called before the video is closed
- gsvf:close (function)
- Event called after the video is closed
- gsvf:destroy (function)
- Event called when the player is "destroyed"
Example:
$('#element').on('gsvf:ready', function(event, options) {
if (options.type == 'vimeo') {
options.player.on('timeupdate', function(data) {
console.log('Time Update:');
console.log(data);
})
}
});
Accessing the Player
The player can be accessed via the player property of the gsvideoframe object. The player object will vary depending on which video provider the video is initialized with.
Example:
$('#element').data('gsvideoframe').player.pauseVideo()
API
- close()
- Closes the embedded video iFrame
- play()
- pause()
- toggle()
- Toggles video play/pause state.
- stop()
- seek()
- Seeks to a specified time in the video
- destroy()
- Destroys the video (note:
beforeClose() and close() events will not be called when destroy() is called)
Example:
$('#element').gsVideoFrame({ ...options });
$('#element').data('gsvideoframe').close();
$('#element').data('gsvideoframe').seek(123);