Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 2f9d805

Browse files
author
matthewcarroll
committed
Implement Material Design Lite for demo pages, minor bug and formatting fixes
1 parent 494dd6f commit 2f9d805

File tree

5 files changed

+212
-118
lines changed

5 files changed

+212
-118
lines changed

player/demo.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ function onApiChange(event){
3939
function onPlayerReady(){
4040
// Update page after player is ready
4141
updateAll();
42+
playVideo();
4243
}
4344

44-
function onPlayerStateChange (event){
45+
function onPlayerStateChange(event){
4546
// Get current state
4647
// Video has ended
4748
switch (event.data) {
@@ -80,14 +81,17 @@ function update(node){
8081
switch (node){
8182
// Update player reported changes
8283
case "duration":
83-
document.getElementById("duration").innerHTML = player.getDuration()+"s"
84+
document.getElementById("duration").innerHTML = player.getDuration()+"s";
8485
break;
8586
case "url":
86-
var url = player.getVideoUrl()
87-
document.getElementById("url").innerHTML = "<a href=\""+url+"\">"+url+"</a>"
87+
var url = player.getVideoUrl();
88+
document.getElementById("url").innerHTML = "<a href=\""+url+"\">"+url+"</a>";
8889
break;
8990
case "embedCode":
90-
document.getElementById("embedCode").innerText = player.getVideoEmbedCode()
91+
var embedCode = player.getVideoEmbedCode();
92+
var index = Math.ceil(embedCode.length/3);
93+
var fmtEmbedCode = [embedCode.slice(0, index), "\n", embedCode.slice(index, index*2),"\n", embedCode.slice(index*2)].join('');
94+
document.getElementById("embedCode").innerText = fmtEmbedCode
9195
break;
9296
case "percentLoaded":
9397
document.getElementById("percentLoaded").innerHTML = player.getVideoLoadedFraction()*100+"%"
@@ -222,8 +226,6 @@ function unmute(){
222226
player.unMute();
223227
};
224228
function setQuality(){
225-
console.log("QUAILTY");
226-
console.log(document.getElementById("qualityOption").value);
227229
player.setPlaybackQuality(document.getElementById("qualityOption").value);
228230
};
229231
function setRate(){

player/event_listeners.html

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
<!-- page title -->
45
<title>YouTube in Your App</title>
5-
6+
<!-- Style imports for Material Design Lite -->
7+
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
8+
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.indigo-pink.min.css">
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
611
<!-- This code loads the iFrame Player API code asynchronously.-->
712
<script src = "https://www.youtube.com/iframe_api"></script>
813

@@ -11,16 +16,46 @@
1116

1217
</head>
1318
<body>
14-
<a href=index.html>Demo</a> | <a href=palyer_control.html>Player Controls and Data</a>| Event Listeners<br>
19+
<!-- Header -->
20+
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
21+
<header class="mdl-layout__header"><div class="mdl-layout__header-row">
22+
<span class="mdl-layout-title">YouTube in Your App</span><div class="mdl-layout-spacer"></div>
23+
<nav class="mdl-navigation">
24+
<a class="mdl-navigation__link" href="index.html">Demo</a>
25+
<a class="mdl-navigation__link" href="player_control.html">Player Controls and Data</a>
26+
<a class="mdl-navigation__link" href="#"><b>Event Listeners</b></a>
27+
</nav></div>
28+
</header>
1529

16-
<!-- The iframe video player will replace this <div> tag. -->
17-
<div id="player"></div>
18-
19-
<!-- div for displaying value status -->
20-
<div id="currentState"></div>
30+
<!-- Page contents -->
31+
<main class="mdl-layout__content"><div class="mdl-grid">
32+
33+
<!-- Player -->
34+
<div class="mdl-cell mdl-cell--7-col">
35+
<!-- The iframe video player will replace this <div> tag. -->
36+
<div id="player"></div>
37+
</div>
2138

22-
<!-- div for displaying rate status for a method you will implement -->
23-
<div id="currentRate"></div>
24-
39+
<!-- Content Card for displaying the video status (implemented) -->
40+
<!-- and the current playback rate (You will implement this later) -->
41+
<div class="mdl-cell mdl-cell--5-col">
42+
<table class="mdl-data-table">
43+
<tr>
44+
<td>Current Player Status:</td>
45+
<td>
46+
<!-- div for displaying value status -->
47+
<span id="currentState"></span>
48+
</td>
49+
</tr>
50+
<tr>
51+
<td>Current Player Rate:</td>
52+
<td>
53+
<!-- div for displaying rate status for a method you will implement -->
54+
<span id="currentState"></span>
55+
</td>
56+
</tr>
57+
</table>
58+
</div>
59+
</div></main></div>
2560
</body>
2661
</html>

player/event_listeners.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,26 @@ function onPlayerReady (){
2424

2525
function onPlayerStateChange(event){
2626
// Get current state
27-
var currentState = "Current state: "
27+
var currentState;
2828
if (event.data == YT.PlayerState.ENDED){
29-
currentState += "Ended";
29+
currentState = "Ended";
3030
}
3131
else if (event.data == YT.PlayerState.PLAYING){
32-
currentState += "Playing";
32+
currentState = "Playing";
3333
}
3434
else if (event.data == YT.PlayerState.PAUSED){
35-
currentState += "Paused";
35+
currentState = "Paused";
3636
}
3737
else if (event.data == YT.PlayerState.BUFFERING){
38-
currentState += "Buffering";
38+
currentState = "Buffering";
3939
}
4040
else if (event.data == YT.PlayerState.CUED){
41-
currentState += "Cued";
41+
currentState = "Cued";
4242
} else{
43-
currentState += "Unknown";
43+
currentState = "Unknown";
4444
}
4545

46+
currentState += " (" + event.data + ")"
4647
// Update video state div
4748
document.getElementById('currentState').innerText = currentState;
4849
};

player/index.html

Lines changed: 116 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,128 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
<!-- page title -->
45
<title>YouTube in Your App</title>
6+
<!-- Style imports for Material Design Lite -->
7+
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
8+
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.indigo-pink.min.css">
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
511
<!-- This code loads the iFrame Player API code asynchronously.-->
612
<script src = "https://www.youtube.com/iframe_api"></script>
713
<!-- This is the source of the Javscript for the demo -->
814
<script src="demo.js"></script>
915
</head>
1016
<body>
11-
Demo | <a href=player_control.html>Player Controls and Data</a> | <a href=event_listeners.html>Event Listeners</a><br>
12-
<!-- The iframe video player will replace this <div> tag. -->
13-
<div id="player"></div>
14-
<br><br>
15-
16-
<!-- This table contains metadata on the video in the iframe -->
17-
<div>Metadata</div>
18-
<table border="1">
19-
<tr>
20-
<td style="width:100px">Title</td>
21-
<td id="title" style="width:500px"></td>
22-
</tr><tr>
23-
<td style="width:100px">Author</td>
24-
<td id="author" style="width:500px"></td>
25-
</tr><tr>
26-
<td style="width:100px">Duration</td>
27-
<td id="duration" style="width:500px"></td>
28-
</tr><tr>
29-
<td style="width:100px">URL</td>
30-
<td id="url" style="width:500px"></td>
31-
</tr><tr>
32-
<td style="width:100px">Embed Code</td>
33-
<td id="embedCode" style="width:500px"></td>
34-
</tr><tr>
35-
<td style="width:100px">% loaded</td>
36-
<td id=percentLoaded style="width:500px"></td>
37-
</tr>
38-
</table>
39-
<br>
40-
41-
<!-- This table contains editable video on the video in the iframe -->
42-
<div>Video Attributes</div>
43-
<table border="1">
44-
<tr>
45-
<td style="width:120px">VideoID</td>
46-
<td style="width:100px" id="video_id"></td>
47-
<td>
48-
<input id="video_idOption" type="text">
49-
<input type="button" value="Load" onClick="loadNewVideo()">
50-
<input type="button" value="Cue" onClick="cueNewVideo()">
51-
</td>
52-
</tr><tr>
53-
<td style="width:120px">Status</td>
54-
<td style="width:100px" id="status"></td>
55-
<td>
56-
<input type="button" value="Play" onClick="playVideo()">
57-
<input type="button" value="Pause" onClick="pauseVideo()">
58-
<input type="button" value="Stop" onClick="stopVideo()">
59-
</td>
60-
</tr><tr>
61-
<td style="width:120px">Current Progress</td>
62-
<td style="width:100px" id="currentTime"></td>
63-
<td type="text">
64-
<input id="currentTimeOption" type="text">
65-
<input type="button" value="Seek" onClick="seekTo()">
66-
</td>
67-
</tr><tr>
68-
<td style="width:120px">Volume (0-100)</td>
69-
<td style="width:100px" id="volume"></td>
70-
<td type="text">
71-
<input id="volumeOption" type="text">
72-
<input type="button" value="Set" onClick="setVolume()">
73-
</td>
74-
</tr><tr>
75-
<td style="width:120px">Muted?</td>
76-
<td style="width:100px" id="mute"></td>
77-
<td>
78-
<input type="button" value="Mute" onClick="mute()">
79-
<input type="button" value="Unmute" onClick="unmute()">
80-
</td>
81-
</tr><tr>
82-
<td style="width:120px">Video Quality</td>
83-
<td style="width:100px" id=quality></td>
84-
<td>
85-
<select id="qualityOption">
86-
</select>
87-
<input type="button" value="Set" onClick="setQuality()">
88-
</td>
89-
</tr><tr>
90-
<td style="width:120px">Playback Rate</td>
91-
<td style="width:100px" id=rate></td>
92-
<td>
93-
<select id="rateOption">
94-
</select>
95-
<input type="button" value="Set" onClick="setRate()">
96-
</td>
97-
</tr>
98-
</table>
17+
<!-- Header -->
18+
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
19+
<header class="mdl-layout__header">
20+
<div class="mdl-layout__header-row">
21+
<!-- Title -->
22+
<span class="mdl-layout-title">YouTube in Your App</span>
23+
<!-- Add spacer, to align navigation to the right -->
24+
<div class="mdl-layout-spacer"></div>
25+
<!-- Navigation. We hide it in small screens. -->
26+
<nav class="mdl-navigation">
27+
<a class="mdl-navigation__link" href="#"><b>Demo</b></a>
28+
<a class="mdl-navigation__link" href="player_control.html">Player Controls and Data</a>
29+
<a class="mdl-navigation__link" href="event_listeners.html">Event Listeners</a>
30+
</nav>
31+
</div>
32+
</header>
33+
<main class="mdl-layout__content">
34+
<div class="mdl-grid">
35+
<div class="mdl-cell mdl-cell--5-col">
36+
<!-- The iframe video player will replace this <div> tag. -->
37+
<div id="player"></div>
38+
</div>
39+
<div class="mdl-cell mdl-cell--7-col">
40+
<!-- This table contains editable video on the video in the iframe -->
41+
<table class="mdl-data-table">
42+
<tr>
43+
<td class="mdl-data-table__cell--non-numeric">VideoID</td>
44+
<td id="video_id"></td>
45+
<td class="mdl-data-table__cell--non-numeric">
46+
<input id="video_idOption" type="text">
47+
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" onClick="loadNewVideo()">Load</button>
48+
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" onClick="cueNewVideo()">Cue</button>
49+
</td>
50+
</tr><tr>
51+
<td class="mdl-data-table__cell--non-numeric">Status</td>
52+
<td id="status"></td>
53+
<td class="mdl-data-table__cell--non-numeric">
54+
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" onClick="playVideo()">Play</button>
55+
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" onClick="pauseVideo()">Pause</button>
56+
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" onClick="stopVideo()">Stop</button>
57+
</td>
58+
</tr><tr>
59+
<td class="mdl-data-table__cell--non-numeric">Current Progress</td>
60+
<td id="currentTime"></td>
61+
<td class="mdl-data-table__cell--non-numeric">
62+
<input id="currentTimeOption" type="text">
63+
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" onClick="seekTo()">Seek</button>
64+
</td>
65+
</tr><tr>
66+
<td class="mdl-data-table__cell--non-numeric">Volume (0-100)</td>
67+
<td id="volume"></td>
68+
<td class="mdl-data-table__cell--non-numeric">
69+
<input id="volumeOption" type="text">
70+
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" onClick="setVolume()">Set</button>
71+
</td>
72+
</tr><tr>
73+
<td class="mdl-data-table__cell--non-numeric">Muted?</td>
74+
<td id="mute"></td>
75+
<td class="mdl-data-table__cell--non-numeric">
76+
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" onClick="mute()">Mute</button>
77+
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" onClick="unmute()">Unmute</button>
78+
</td>
79+
</tr><tr>
80+
<td class="mdl-data-table__cell--non-numeric">Video Quality</td>
81+
<td id=quality></td>
82+
<td class="mdl-data-table__cell--non-numeric">
83+
<select id="qualityOption">
84+
</select>
85+
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" onClick="setQuality()">Set</button>
86+
</td>
87+
</tr><tr>
88+
<td class="mdl-data-table__cell--non-numeric">Playback Rate</td>
89+
<td id=rate></td>
90+
<td class="mdl-data-table__cell--non-numeric">
91+
<select id="rateOption">
92+
</select>
93+
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" onClick="setRate()">Set</button>
94+
</td>
95+
</tr>
96+
</table>
97+
</div>
98+
</div>
99+
<div class="mdl-grid">
100+
<div class="mdl-cell mdl-cell--4-col">
101+
<!-- This table contains metadata on the video in the iframe -->
102+
<table class="mdl-data-table">
103+
<tr>
104+
<td class="mdl-data-table__cell--non-numeric">Title</td>
105+
<td id="title" class="mdl-data-table__cell--non-numeric"></td>
106+
</tr><tr>
107+
<td class="mdl-data-table__cell--non-numeric">Author</td>
108+
<td id="author" class="mdl-data-table__cell--non-numeric"></td>
109+
</tr><tr>
110+
<td class="mdl-data-table__cell--non-numeric">Duration</td>
111+
<td id="duration"></td>
112+
</tr><tr>
113+
<td class="mdl-data-table__cell--non-numeric">% loaded</td>
114+
<td id=percentLoaded></td>
115+
</tr><tr>
116+
<td class="mdl-data-table__cell--non-numeric">Embed Code</td>
117+
<td id="embedCode"></td>
118+
</tr><tr>
119+
<td class="mdl-data-table__cell--non-numeric">URL</td>
120+
<td id="url"></td>
121+
</tr>
122+
</table>
123+
</div>
124+
</div>
125+
</main>
126+
</div>
99127
</body>
100128
</html>

0 commit comments

Comments
 (0)