소스 검색

auto-push

Coldiary 5 년 전
부모
커밋
580c9e13b7
5개의 변경된 파일371개의 추가작업 그리고 48개의 파일을 삭제
  1. 188
    1
      css/player.css
  2. 23
    3
      index.html
  3. 3
    4
      js/init.js
  4. 4
    0
      js/jquery-2.1.4.min.js
  5. 153
    40
      js/player.js

+ 188
- 1
css/player.css 파일 보기

1
 * { margin:0; padding:0; }
1
 * { margin:0; padding:0; }
2
 
2
 
3
+
3
 div#player {
4
 div#player {
5
+	 -webkit-touch-callout: none;
6
+    -webkit-user-select: none;
7
+    -khtml-user-select: none;
8
+    -moz-user-select: none;
9
+    -ms-user-select: none;
10
+    user-select: none;
4
 	background-color: #333;
11
 	background-color: #333;
5
 	height: 30px;
12
 	height: 30px;
6
 	position: absolute;
13
 	position: absolute;
9
 	color: white;
16
 	color: white;
10
 	padding-left: 20px;
17
 	padding-left: 20px;
11
 	line-height: 30px;
18
 	line-height: 30px;
12
-	letter-spacing: 10px;
19
+	letter-spacing: 5px;
20
+	cursor: default;
21
+	box-sizing: border-box;
22
+}
23
+
24
+div#player div#player-control {
25
+	float: left;
26
+	margin-right: 5px;
27
+}
28
+
29
+div#player a#player-menu,
30
+div#player div#player-volume {
31
+	float: right;
32
+	margin-left: 10px; 
33
+}
34
+
35
+div#player div {
36
+	display: inline-block;
37
+	vertical-align: top;
38
+}
39
+
40
+div#player div#player-bar {
41
+	position: relative;
42
+	height: 5px;
43
+	width: 500px;
44
+	margin-top: 12px;
45
+	border: 1px solid #AAA;
46
+	cursor: pointer;
47
+}
48
+
49
+div#player div#player-cursor {
50
+	position: absolute;
51
+	height: 15px;
52
+	width: 2px;
53
+	top: 2px;
54
+	transform: translate(0px, -50%);
55
+	transition: left 1s;
56
+	background-color: #FFF;
57
+}
58
+
59
+div#player div#player-played {
60
+	position: absolute;
61
+	height: 5px;
62
+	top: 0px;
63
+	left: 0px;
64
+	transition: width 1s;
65
+	background-color: #DDD;
66
+}
67
+
68
+div#player div#player-buffer {
69
+	position: absolute;
70
+	height: 5px;
71
+	top: 0px;
72
+	left: 0px;
73
+	transition: width 1s;
74
+	background-color: #888;
75
+}
76
+
77
+div#player span#player-title {
78
+	max-width: 300px;
79
+	overflow: hidden;
80
+	text-overflow: ellipsis;
81
+	word-wrap: break-word;
82
+	white-space: nowrap;
83
+}
84
+
85
+span#player-duration,
86
+span#player-currentTime {
87
+	font-size: 0.8em;
88
+}
89
+
90
+div#player #player-volume-bar {
91
+	position: relative;
92
+	height: 5px;
93
+	width: 100px;
94
+	margin-top: 12px;
95
+	border: 1px solid #AAA;
96
+	cursor: pointer;
97
+}
98
+
99
+div#player div#player-volume-set {
100
+	position: absolute;
101
+	height: 5px;
102
+	width: 100%;
103
+	top: 0px;
104
+	left: 0px;
105
+	background-color: #DDD;
13
 }
106
 }
14
 
107
 
15
 div#player a:hover {
108
 div#player a:hover {
22
 	top: 50%;
115
 	top: 50%;
23
 	left: 50%;
116
 	left: 50%;
24
 	transform: translate(-50%, -50%);
117
 	transform: translate(-50%, -50%);
118
+}
119
+
120
+input[type=range] {
121
+  -webkit-appearance: none; /* Hides the slider so that custom slider can be made */
122
+  width: 100%; /* Specific width is required for Firefox. */
123
+  height: 10px;
124
+}
125
+
126
+input[type=range]::-webkit-slider-thumb {
127
+  -webkit-appearance: none;
128
+}
129
+
130
+input[type=range]:focus {
131
+  outline: none; /* Removes the blue border. You should probably do some kind of focus styling for accessibility reasons though. */
132
+}
133
+
134
+input[type=range]::-ms-track {
135
+  width: 100%;
136
+  cursor: pointer;
137
+  background: transparent; /* Hides the slider so custom styles can be added */
138
+  border-color: transparent;
139
+  color: transparent;
140
+}
141
+
142
+/* Special styling for WebKit/Blink */
143
+input[type=range]::-webkit-slider-thumb {
144
+  -webkit-appearance: none;
145
+  border: 1px solid #fff;
146
+  height: 10px;
147
+  width: 2px;
148
+  background: #ffffff;
149
+  cursor: pointer;
150
+  margin-top: -2px;
151
+  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; /* Add cool effects to your sliders! */
152
+}
153
+
154
+/* All the same stuff for Firefox */
155
+input[type=range]::-moz-range-thumb {
156
+  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
157
+  border: 1px solid #000000;
158
+  height: 10px;
159
+  width: 2px;
160
+  background: #ffffff;
161
+  cursor: pointer;
162
+}
163
+
164
+/* All the same stuff for IE */
165
+input[type=range]::-ms-thumb {
166
+  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
167
+  border: 1px solid #fff;
168
+  height: 10px;
169
+  width: 2px;
170
+  background: #fff;
171
+  cursor: pointer;
172
+}
173
+
174
+input[type=range]::-webkit-slider-runnable-track {
175
+  width: 100%;
176
+  height: 5px;
177
+  cursor: pointer;
178
+  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
179
+  background: #fff;
180
+  border: 0.2px solid #010101;
181
+}
182
+
183
+input[type=range]::-moz-range-track {
184
+  width: 100%;
185
+  height: 5px;
186
+  cursor: pointer;
187
+  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
188
+  background: #fff;
189
+  border: 0.2px solid #010101;
190
+}
191
+
192
+input[type=range]::-ms-track {
193
+  width: 100%;
194
+  height: 5px;
195
+  cursor: pointer;
196
+  background: transparent;
197
+  border-color: transparent;
198
+  border-width: 16px 0;
199
+  color: transparent;
200
+}
201
+
202
+input[type=range]::-ms-fill-lower {
203
+  background: #2a6495;
204
+  border: 0.2px solid #010101;
205
+  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
206
+}
207
+
208
+input[type=range]::-ms-fill-upper {
209
+  background: #3071a9;
210
+  border: 0.2px solid #010101;
211
+  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
25
 }
212
 }

+ 23
- 3
index.html 파일 보기

3
 <head>
3
 <head>
4
 	<meta charset="utf-8">
4
 	<meta charset="utf-8">
5
 	<title></title>
5
 	<title></title>
6
+	<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
6
 	<script type="text/javascript" src="js/player.js"></script>
7
 	<script type="text/javascript" src="js/player.js"></script>
7
 	<link rel="stylesheet" type="text/css" href="css/player.css">
8
 	<link rel="stylesheet" type="text/css" href="css/player.css">
8
 </head>
9
 </head>
9
 <body>
10
 <body>
10
 	<div id="player">
11
 	<div id="player">
11
-		<a id="player-previous">«</a>
12
-		<a id="player-toggle">⧐</a>
13
-		<a id="player-next">»</a>
12
+		<div id="player-control">
13
+			<a id="player-previous">«</a>
14
+			<a id="player-toggle">▻</a>
15
+			<a id="player-next">»</a>
16
+		</div>
17
+		<span id="player-title">No Song</span>
18
+		<div id="player-bar">
19
+			<div id="player-buffer"></div>
20
+			<div id="player-played"></div>
21
+			<div id="player-cursor"></div>
22
+		</div>
23
+		<div id="player-time">
24
+			<span id="player-currentTime">00:00</span> | <span id="player-duration">00:00</span>
25
+		</div>
26
+		<a id="player-menu">☰</a>
27
+		<div id="player-volume">
28
+			<a id="player-volume-mute">♫</a>
29
+			<input type="range" id="player-volume-bar" min="0" max="100" value="100"/>
30
+			<!-- <div id="player-volume-bar">
31
+				<div id="player-volume-set"></div>
32
+			</div> -->
33
+		</div>
14
 	</div>
34
 	</div>
15
 	<div id="YTplayer"></div>
35
 	<div id="YTplayer"></div>
16
 	<script type="text/javascript" src="js/init.js"></script>
36
 	<script type="text/javascript" src="js/init.js"></script>

+ 3
- 4
js/init.js 파일 보기

1
 evaplayer = new Player([
1
 evaplayer = new Player([
2
 {
2
 {
3
 	title: "Musique 1",
3
 	title: "Musique 1",
4
-	link:"519_pOvP9xs"
4
+	link: "https://www.youtube.com/watch?v=519_pOvP9xs"
5
 },
5
 },
6
 {
6
 {
7
 	title: "Musique 2",
7
 	title: "Musique 2",
8
-	link: "519_pOvP9xs"
8
+	link: "https://www.youtube.com/watch?v=etmSWkeRYbk"
9
 }
9
 }
10
 ]);
10
 ]);
11
-console.log(evaplayer);
12
-
11
+console.log(evaplayer);

+ 4
- 0
js/jquery-2.1.4.min.js
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


+ 153
- 40
js/player.js 파일 보기

1
 function Player(sources) {
1
 function Player(sources) {
2
 	this.playlist = sources;
2
 	this.playlist = sources;
3
 	this.current = {};
3
 	this.current = {};
4
+	this.volume = 100;
5
+	this.currentSong = -1;
4
 	this.isPlaying = false;
6
 	this.isPlaying = false;
5
-	this.player;
7
+	this.isMute = false;
8
+	this.rate = 500;
6
 	this.YTplayer = false;
9
 	this.YTplayer = false;
10
+	this.controls = {};
11
+	this.interval = null;
7
 
12
 
8
 	this.init = function() {
13
 	this.init = function() {
9
 		this.loadYTplayer();
14
 		this.loadYTplayer();
15
+		this.bindControls();
10
 		this.bindEvents();
16
 		this.bindEvents();
11
-		console.log('init...');
12
 	}
17
 	}
13
 
18
 
14
 	this.bindEvents = function() {
19
 	this.bindEvents = function() {
15
-		var toggle = document.getElementById('player-toggle');
16
-		toggle.addEventListener('click', this.toggle);
17
-		var previous = document.getElementById('player-previous');
18
-		previous.addEventListener('click', this.previous);
19
-		var next = document.getElementById('player-next');
20
-		next.addEventListener('click', this.next);
20
+		this.controls.toggle.addEventListener('click', this.toggle);
21
+		this.controls.previous.addEventListener('click', this.previous);
22
+		this.controls.next.addEventListener('click', this.next);
23
+		this.controls.bar.addEventListener('click', this.seekPosition);
24
+		this.controls.volume.addEventListener('input', this.setVolume);
25
+		this.controls.volumeMute.addEventListener('click', this.setMute);
21
 	}
26
 	}
22
 
27
 
23
-	this.newSong = function (videoId) {
24
-		if (this.YTplayer)
25
-			this.YTplayer.parentNode.removeChild(this.YTplayer);
26
-		this.YTplayer = new YT.Player('YTplayer', {
27
-			height: '0',
28
-			width: '0',
29
-			videoId: videoId,
30
-			playerVars: {
31
-
32
-			},
33
-			events: {
34
-				'onReady': onPlayerReady,
35
-				'onStateChange': onPlayerStateChange
36
-			}
37
-		});
28
+	this.bindControls = function() {
29
+		this.controls.toggle = document.getElementById('player-toggle');
30
+		this.controls.next = document.getElementById('player-next');
31
+		this.controls.previous = document.getElementById('player-previous');
32
+		this.controls.volume = document.getElementById('player-volume-bar');
33
+		this.controls.volumeSet = document.getElementById('player-volume-set');
34
+		this.controls.volumeMute = document.getElementById('player-volume-mute');
35
+		this.controls.bar = document.getElementById('player-bar');
36
+		this.controls.buffer = document.getElementById('player-buffer');
37
+		this.controls.played = document.getElementById('player-played');
38
+		this.controls.cursor = document.getElementById('player-cursor');
39
+		this.controls.duration = document.getElementById('player-duration');
40
+		this.controls.currentTime = document.getElementById('player-currentTime');
41
+		this.controls.title = document.getElementById('player-title');
42
+	}
43
+
44
+	this.getVideoID = function(url) {
45
+		re = /\?v=([^&]*)/;
46
+		match = re.exec(url);
47
+		return (match && match.length >= 2 ? match[1] : '');
48
+	}
49
+
50
+	this.newSong = function (url) {
51
+		if (!this.YTplayer) {
52
+			this.YTplayer = new YT.Player('YTplayer', {
53
+				height: '0',
54
+				width: '0',
55
+				videoId: this.getVideoID(url),
56
+				events: {
57
+					'onReady': onPlayerReady,
58
+					'onStateChange': onPlayerStateChange
59
+				}
60
+			});
61
+		} else {
62
+			this.YTplayer.loadVideoById(this.getVideoID(url));
63
+		}
64
+		this.isPlaying = true;
38
 	}
65
 	}
39
 
66
 
40
 	this.loadYTplayer = function() {
67
 	this.loadYTplayer = function() {
44
 		firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
71
 		firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
45
 	};
72
 	};
46
 
73
 
47
-	this.seekPosition = function() {};
74
+	this.getState = function() {
75
+		var current = this.YTplayer.getCurrentTime();
76
+		var bufferized = this.YTplayer.getVideoLoadedFraction() * 100;
77
+		var duration = this.current.duration;
78
+		var fraction = (current / duration) * 100;
79
+		this.controls.played.style.width = fraction + '%';
80
+		this.controls.buffer.style.width = bufferized + '%';
81
+		this.controls.cursor.style.left = fraction + '%';
82
+		current = new Date(current * 1000);
83
+		current = current.toTimeString().substr(3, 6);
84
+		this.controls.currentTime.textContent = current;
85
+	}
86
+
87
+	this.seekPosition = function() {
88
+		var duration = evaplayer.current.duration;
89
+		var fraction = (event.offsetX / evaplayer.controls.bar.clientWidth) * 100;
90
+		var timeseeked = (duration * fraction) / 100;
91
+		evaplayer.YTplayer.seekTo(timeseeked);
92
+	};
93
+
94
+	this.setVolume = function() {
95
+		evaplayer.YTplayer.setVolume(event.target.value);
96
+		evaplayer.volume = event.target.value;
97
+	};
98
+
99
+	this.setMute = function() {
100
+		if (!evaplayer.isMute) {
101
+			evaplayer.YTplayer.mute();
102
+			evaplayer.controls.volume.value = 0;
103
+			evaplayer.controls.volumeMute.style.textDecoration = 'line-through';
104
+		} else {
105
+			evaplayer.YTplayer.unMute();
106
+			evaplayer.controls.volume.value = evaplayer.volume;
107
+			evaplayer.controls.volumeMute.style.textDecoration = 'none';
108
+		}
109
+		evaplayer.isMute = !evaplayer.isMute;
110
+	};
111
+
48
 	this.toggle = function() {
112
 	this.toggle = function() {
49
-		if (evaplayer.isPlaying) {
113
+		if (evaplayer.isPlaying)
50
 			evaplayer.YTplayer.pauseVideo();
114
 			evaplayer.YTplayer.pauseVideo();
51
-		} else {
115
+		else
52
 			evaplayer.YTplayer.playVideo();
116
 			evaplayer.YTplayer.playVideo();
53
-		}
54
 		evaplayer.isPlaying = !evaplayer.isPlaying;
117
 		evaplayer.isPlaying = !evaplayer.isPlaying;
55
 		return evaplayer;
118
 		return evaplayer;
56
 	};
119
 	};
120
+
57
 	this.next = function() {
121
 	this.next = function() {
58
-		return 
122
+		evaplayer.currentSong++;
123
+		if (evaplayer.currentSong > evaplayer.playlist.length - 1)
124
+			evaplayer.currentSong = 0;
125
+		evaplayer.newSong(evaplayer.playlist[evaplayer.currentSong].link);
59
 	};
126
 	};
60
-	this.previous = function() {};
61
-	this.init();
62
-};
63
 
127
 
64
-function onYouTubeIframeAPIReady() {
65
-	evaplayer.newSong('519_pOvP9xs');
66
-}
128
+	this.previous = function() {
129
+		evaplayer.currentSong--;
130
+		if (evaplayer.currentSong < 0)
131
+			evaplayer.currentSong = evaplayer.playlist.length - 1;
132
+		evaplayer.newSong(evaplayer.playlist[evaplayer.currentSong].link);
133
+	};
134
+
135
+	this.updateInfo = function() {
136
+		var data = this.YTplayer.getVideoData();
137
+		var duration = this.YTplayer.getDuration();
138
+		this.current = {
139
+			author: data.author,
140
+			title: data.title,
141
+			duration: duration
142
+		};
143
+		var title = this.current.title;
144
+		if (this.current.author)
145
+			title = this.current.author + ' - ' + title;
146
+		this.controls.title.textContent = title;
147
+		var duration = this.current.duration;
148
+		duration = new Date(duration * 1000);
149
+		duration = duration.toTimeString().substr(3, 6);
150
+		this.controls.duration.textContent = duration;
151
+	};
67
 
152
 
68
-function onPlayerReady(event) {
69
-	event.target.playVideo();
70
-}
153
+	function onPlayerReady(event) {
154
+		event.target.playVideo();
155
+		if (!evaplayer.interval)
156
+			evaplayer.interval = setInterval(function() {
157
+				evaplayer.getState();
158
+			}, evaplayer.rate);
159
+	}
71
 
160
 
72
-function onPlayerStateChange(event) {
73
-	if (event.data == YT.PlayerState.PLAYING && !evaplayer.isPlaying) {
74
-		evaplayer.isPlaying = true;
161
+	function onPlayerStateChange(event) {
162
+		switch (event.data) {
163
+			case YT.PlayerState.PLAYING: 
164
+				evaplayer.isPlaying = true;
165
+				evaplayer.updateInfo();
166
+				evaplayer.controls.toggle.textContent = '◻';
167
+				if (!evaplayer.interval)
168
+					evaplayer.interval = setInterval(function() {
169
+						evaplayer.getState();
170
+					}, evaplayer.rate);
171
+				break;
172
+			case YT.PlayerState.ENDED:
173
+				evaplayer.next();
174
+				break;
175
+			case YT.PlayerState.PAUSED:
176
+				evaplayer.isPlaying = false;
177
+				evaplayer.controls.toggle.textContent = '▻';
178
+				clearInterval(evaplayer.interval);
179
+				evaplayer.interval = null;
180
+				break;
181
+		}
75
 	}
182
 	}
183
+
184
+	this.init();
185
+};
186
+
187
+function onYouTubeIframeAPIReady() {
188
+	evaplayer.next();
76
 }
189
 }