Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var tag = document.createElement('script');
- tag.src = "https://www.youtube.com/iframe_api";
- var firstScriptTag = document.getElementsByTagName('script')[0];
- firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
- var player;
- function onYouTubeIframeAPIReady() {
- player = new YT.Player('player', {
- height: '390',
- width: '640',
- videoId: 'novideoid',
- events: {
- 'onReady': onPlayerReady,
- 'onStateChange': onPlayerStateChange
- }
- });
- }
- // 4. The API will call this function when the video player is ready.
- function onPlayerReady(event) {
- $('.open-popup').click(function() {
- event.target.playVideo();
- });
- $('.close-popup').click(function(e) {
- player.stopVideo();
- });
- }
- // 5. The API calls this function when the player's state changes.
- // The function indicates that when playing a video (state=1),
- // the player should play for six seconds and then stop.
- var done = false;
- function onPlayerStateChange(event) {
- if(event.data === 0) {
- $('.close.close-popup').click();
- }
- }
- function stopVideo() {
- player.stopVideo();
- }
- $(function () {
- onYouTubeIframeAPIReady();
- $('#myModal').on('show.bs.modal', function(e) {
- var videoId = $(e.relatedTarget).data('video-id');
- var x = new String(videoId);
- player.loadVideoById(x);
- });
- });
Add Comment
Please, Sign In to add comment