-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.html
70 lines (67 loc) · 1.69 KB
/
2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE HTML>
<html>
<head>
<title>Youtube IFrame API</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="//www.youtube.com/player_api"></script>
<style type="text/css">
.main-content{
width: fit-content;
margin: 0px auto;
margin-top: 50px;
}
.main-content > iframe{
height: 250px;
margin: 0px auto;
float: none;
padding: 25px;
border: 2px solid #e1e1e2;
background: #eee;
}
</style>
</head>
<body>
<div class="main-content">
<iframe src="https://www.youtube.com/embed/phhtPnUlAUs?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
<iframe src="https://www.youtube.com/embed/phhtPnUlAUs?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
<iframe src="https://www.youtube.com/embed/phhtPnUlAUs?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
</div>
<!-- Javascript/Jquery -->
<script type="text/javascript">
var vids = [];
$(document).ready(function(){
setTimeout(function(){
$('.main-content iframe').each(function(e){
player = new YT.Player(this, {
events:{
'onStateChange': onPlayerStateChange
}
});
vids.push(player);
});
}, 5000);
});
function onPlayerStateChange(event){
if(event.data == YT.PlayerState.PLAYING){
console.log("Playing..");
// TO Perform Action
// 1. To Pause All Youtube Videos
console.log(event.target);
pauseYTVideos(event)
}else if(event.data == YT.PlayerState.PAUSED){
console.log("Pause....");
// TO Perform Action
}else{
console.log("State Changed...");
// TO Perform Action
}
}
function pauseYTVideos(event){
for(var i=0; i<vids.length; i++){
if(event.target!=vids[i])
vids[i].pauseVideo();
}
}
</script>
</body>
</html>