Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: chrome/browser/resources/mediaplayer.html

Issue 7067020: Moving mediaplayer to the chrome filebrowser. Observable behaviour should not change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolved conflicts. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE HTML>
2 <html i18n-values="dir:textdirection;">
3 <head>
4 <meta charset="utf-8">
5 <title>Media Player</title>
6 <style type="text/css">
7
8 body {
9 overflow: hidden;
10 background: black;
11 }
12
13 .error {
14 left: 0;
15 right: 0;
16 color: white;
17 bottom: 38px;
18 position: absolute;
19 }
20
21 .glow {
22 left: 0;
23 right: 0;
24 bottom: 30px;
25 height: 8px;
26 opacity: .4;
27 position: absolute;
28 background: -webkit-linear-gradient(transparent, white);
29 }
30
31 .audiotitle {
32 left: 0;
33 right: 0;
34 text-align: center;
35 position: absolute;
36 color: white;
37 top: 100px;
38 }
39
40 .progress {
41 -webkit-appearance: sliderthumb-horizontal;
42 position: absolute;
43 background: transparent;
44 left: 93px;
45 right: 120px;
46 bottom: -2px;
47 height: 30px;
48 z-index: 99999;
49 border-left: 1px solid #424242;
50 }
51
52 .playercontrolsbox {
53 bottom: 0;
54 left: 0;
55 height: 30px;
56 right: 0;
57 position: absolute;
58 }
59
60 .videocontrols {
61 top: 0;
62 left: 0;
63 z-index: 999;
64 height: 100%;
65 opacity: .9;
66 right: 0;
67 position: absolute;
68 background: -webkit-linear-gradient(#323232, #070707);
69 }
70
71 .sliderback {
72 bottom: 12px;
73 left: 93px;
74 right: 120px;
75 height: 5px;
76 position: absolute;
77 border-radius: 3px;
78 background: -webkit-linear-gradient(#ced9fa, #e8ecf9);
79 border: 1px solid #ffffff;
80 }
81
82 .sliderplayed {
83 height: 100%;
84 width:0;
85 left: -1px;
86 top: -1px;
87 border-radius: 3px;
88 border: 1px solid #9ca5b7;
89 position: absolute;
90 background: -webkit-linear-gradient(#4a5d84, #232c3d);
91 }
92
93 .sliderloaded {
94 height: 100%;
95 width:0;
96 left: -1px;
97 top: -1px;
98 border-radius: 3px;
99 position: absolute;
100 background: #6a799a;
101 border: 1px solid #ffffff;
102 }
103
104 .audiocontrols {
105 top: 0;
106 left: 0;
107 z-index: 999;
108 height: 100%;
109 opacity: .9;
110 right: 0;
111 position: absolute;
112 background: -webkit-linear-gradient(#323232, #070707);
113 }
114
115 .soundbutton {
116 position: absolute;
117 right: 30px;
118 bottom: 0;
119 border-left: 1px solid #424242;
120 border-right: 1px solid black;
121 }
122
123 .soundiconhigh {
124 /* background: TODO(serya): Restore mediaplayer_vol_high.png after moving medi aplayer to extension. */
125 }
126
127 .soundiconmuted {
128 /* background: TODO(serya): Restore mediaplayer_vol_mute.png after moving medi aplayer to extension. */
129 }
130
131 .soundiconhigh,
132 .soundiconmuted {
133 background-repeat: no-repeat;
134 background-position: 6px 8px;
135 }
136
137 .volume {
138 position: absolute;
139 bottom: 30px;
140 height: 80px;
141 width: 30px;
142 right: 30px;
143 z-index: 99999;
144 background: black;
145 background: -webkit-linear-gradient(#323232, #070707);
146 }
147
148 .fullscreen {
149 position: absolute;
150 right: 60px;
151 bottom: 0;
152 border-left: 1px solid #424242;
153 border-right: 1px solid black;
154 }
155
156 .fullscreenicon {
157 /* background: TODO(serya): Restore mediaplayer_full_screen.png after moving m ediaplayer to extension. */
158 background-repeat: no-repeat;
159 background-position: 6px 8px;
160 }
161
162 .fullscreenexiticon {
163 /* background: TODO(serya): Restore mediaplayer_full_screen_exit.png after mov ing mediaplayer to extension. */
164 background-repeat: no-repeat;
165 background-position: 6px 8px;
166 }
167
168 .volumeslider {
169 -webkit-appearance: slider-vertical;
170 position: absolute;
171 left: 0;
172 right: 0;
173 bottom: 0;
174 top: 0;
175 }
176
177 .playbutton {
178 position: absolute;
179 left: 30px;
180 bottom: 0;
181 border-left: 1px solid #424242;
182 border-right: 1px solid black;
183 }
184
185 .playicon {
186 /* background: TODO(serya): Restore mediaplayer_play.png after moving mediapla yer to extension. */
187 background-repeat: no-repeat;
188 background-position: 9px 8px;
189 }
190
191 .pausebutton {
192 position: absolute;
193 left: 30px;
194 bottom: 0;
195 border-left: 1px solid #424242;
196 border-right: 1px solid black;
197 }
198
199 .pauseicon {
200 /* background: Restore mediaplayer_pause.png after moving mediaplayer to exten sion. */
201 background-repeat: no-repeat;
202 background-position: 9px 8px;
203 }
204
205 .prevbutton {
206 position: absolute;
207 left: 0;
208 bottom: 0;
209 border-right: 1px solid black;
210 }
211
212 .previcon {
213 /* background: TODO(serya): Restore mediaplayer_prev.png after moving mediapla yer to extension. */
214 background-repeat: no-repeat;
215 background-position: 6px 8px;
216 }
217
218 .playbackvideoelement {
219 width: 100%;
220 height: 100%;
221 position: absolute;
222 left: 0;
223 top: 0;
224 -webkit-transform: translateZ(0);
225 }
226
227 .duration {
228 right: 90px;
229 color: white;
230 position: absolute;
231 top: 8.5px;
232 font-size: .6em;
233 height: 30px;
234 }
235
236 .playbackaudioelement {
237 width: 100%;
238 height: 100%;
239 position: absolute;
240 left: 0;
241 top: 0;
242 }
243
244 .nextbutton {
245 position: absolute;
246 left: 60px;
247 bottom: 0;
248 border-left: 1px solid #424242;
249 border-right: 1px solid black;
250 }
251
252 .nexticon {
253 /* background: TODO(serya): Restore mediaplayer_next.png after moving mediapla yer to extension. */
254 background-repeat: no-repeat;
255 background-position: 6px 8px;
256 }
257
258 .playlistbutton {
259 position: absolute;
260 right: 0;
261 bottom: 0;
262 border-left: 1px solid #424242;
263 border-right: 1px solid black;
264 }
265
266 .playlisticon {
267 /* background: TODO(serya): Restore mediaplayer_playlist.png after moving medi aplayer to extension. */
268 background-repeat: no-repeat;
269 background-position: 6px 8px;
270 }
271
272 .controlbutton {
273 z-index: 9999;
274 cursor: pointer;
275 width: 28px;
276 height: 30px;
277 }
278
279 .controlbutton:hover {
280 background: -webkit-linear-gradient(#6a7eac, #000);
281 }
282
283 .icon {
284 width: 100%;
285 height: 100%;
286 z-index: 9999;
287 }
288
289 </style>
290 <script src="shared/js/local_strings.js"></script>
291 <script src="shared/js/media_common.js"></script>
292 <script>
293
294 function $(o) {
295 return document.getElementById(o);
296 }
297
298 var videoPlaybackElement = null;
299 var audioPlaybackElement = null;
300 var currentPlaylist = null;
301 var currentItem = -1;
302 var savedVolumeValue = 0;
303 var hideVolumeTimerId = 0;
304 var localStrings;
305 var fullScreen = false;
306
307 ///////////////////////////////////////////////////////////////////////////////
308 // Document Functions:
309 /**
310 * Window onload handler, sets up the page.
311 */
312 function load() {
313 document.body.addEventListener('dragover', function(e) {
314 if (e.preventDefault) e.preventDefault();
315 });
316 document.body.addEventListener('drop', function(e) {
317 if (e.preventDefault) e.preventDefault();
318 });
319 document.body.addEventListener('keydown', onkeydown);
320
321 localStrings = new LocalStrings();
322 chrome.send('getCurrentPlaylist', []);
323 }
324
325 function onMediaProgress() {
326 var element = getMediaElement();
327 var current = element.currentTime;
328 var duration = element.duration;
329 var progress = $('progress');
330 progress.value = (current*100)/duration;
331 var played = $('sliderplayed');
332 played.style.width = '' + progress.value + '%';
333 if (progress.value == 100) {
334 onMediaComplete();
335 }
336 }
337
338 function onLoadedProgress(e) {
339 var element = $('sliderloaded');
340 if (e.lengthComputable) {
341 element.style.display = 'block';
342 var percent = (e.loaded * 100) / e.total;
343 element.style.width = '' + percent + '%';
344 } else {
345 element.style.display = 'none';
346 }
347 }
348
349 function onMediaError(e) {
350 console.log('Got new error');
351 console.log(e);
352 chrome.send('playbackError', ['Error playing back',
353 currentPlaylist[currentItem].path]);
354 if (currentPlaylist.length == 1) {
355 $('error').textContent = localStrings.getString('errorstring');
356 } else {
357 chrome.send("showPlaylist", []);
358 }
359 onMediaComplete();
360 }
361
362 function onMediaComplete() {
363 currentItem ++;
364 if (currentItem >= currentPlaylist.length) {
365 currentItem -= 1;
366 var element = getMediaElement();
367 if (!getMediaElement().error) {
368 element.currentTime = 0;
369 element.pause();
370 onMediaProgress();
371 }
372 onMediaPause();
373 return;
374 }
375 var mediaElement = getMediaElement();
376 mediaElement.removeEventListener("progress", onLoadedProgress, true);
377 mediaElement.removeEventListener("timeupdate", onMediaProgress, true);
378 mediaElement.removeEventListener("durationchange", onMetadataAvail, true);
379 // MediaElement.removeEventListener("ended", onMediaComplete, true);
380 mediaElement.removeEventListener("play", onMediaPlay, true);
381 mediaElement.removeEventListener("pause", onMediaPause, true);
382 mediaElement.onerror = undefined;
383 chrome.send('currentOffsetChanged', ['' + currentItem]);
384 playMediaFile(currentPlaylist[currentItem].path);
385 }
386
387 function onMediaPlay() {
388 var pausebutton = $('pausebutton');
389 var playbutton = $('playbutton');
390 pausebutton.style.display = 'block';
391 playbutton.style.display = 'none';
392 }
393
394 function onMediaPause() {
395 var pausebutton = $('pausebutton');
396 var playbutton = $('playbutton');
397 playbutton.style.display = 'block';
398 pausebutton.style.display = 'none';
399 }
400
401 function setupMediaEvents(element) {
402 element.addEventListener("progress", onLoadedProgress, true);
403 element.addEventListener("timeupdate", onMediaProgress, true);
404 element.addEventListener("durationchange", onMetadataAvail, true);
405 // element.addEventListener("ended", onMediaComplete, true);
406 element.onerror = onMediaError;
407 element.addEventListener("play", onMediaPlay, true);
408 element.addEventListener("pause", onMediaPause, true);
409 element.oncontextmenu = function() {
410 return false;
411 };
412 }
413
414 function getMediaElement() {
415 var mediaElement;
416 if (videoPlaybackElement) {
417 mediaElement = videoPlaybackElement;
418 } else {
419 mediaElement = audioPlaybackElement;
420 }
421 return mediaElement;
422 }
423
424 function playPauseButtonClick() {
425 var mediaElement = getMediaElement();
426 if (mediaElement.paused || mediaElement.ended) {
427 mediaElement.play();
428 } else {
429 mediaElement.pause();
430 }
431 }
432
433 function prevButtonClick() {
434 var element = getMediaElement();
435 if (element.currentTime > 6) {
436 element.currentTime = 0;
437 return;
438 }
439 currentItem --;
440 if (currentItem < 0) {
441 currentItem = -1;
442 return;
443 }
444 chrome.send('currentOffsetChanged', ['' + currentItem]);
445 playMediaFile(currentPlaylist[currentItem].path);
446 }
447
448 function nextButtonClick() {
449 currentItem ++;
450 if (currentItem >= currentPlaylist.length) {
451 currentItem = -1;
452 return;
453 }
454 chrome.send('currentOffsetChanged', ['' + currentItem]);
455 playMediaFile(currentPlaylist[currentItem].path);
456 }
457
458 function userChangedProgress() {
459 var val = $('progress').value;
460 var element = getMediaElement();
461 if (element.seekable && element.duration) {
462 var current = (progress.value * element.duration)/100;
463 element.currentTime = current;
464 }
465 }
466
467 function changeVolumeVisibility(visible) {
468 var volume = $('volume');
469 volume.style.display = visible ? 'block' : 'none';
470 }
471
472 function showVolume() {
473 if (hideVolumeTimerId) {
474 clearTimeout(hideVolumeTimerId);
475 hideVolumeTimerId = 0;
476 }
477
478 changeVolumeVisibility(true);
479 }
480
481 function hideVolume() {
482 if (!hideVolumeTimerId)
483 hideVolumeTimerId = setTimeout('changeVolumeVisibility(false)', 500);
484 }
485
486 function volumeChange() {
487 var volumeslider = $('volumeslider');
488 var element = getMediaElement();
489 element.volume = (volumeslider.value/100);
490
491 var soundicon = $('soundicon');
492 soundicon.className = soundicon.className.replace(
493 /soundicon.*/,
494 element.volume > 0 ? 'soundiconhigh' : 'soundiconmuted');
495 }
496
497 function muteVolume(mute) {
498 var volumeslider = $('volumeslider');
499 var element = getMediaElement();
500 if (mute) {
501 savedVolumeValue = volumeslider.value;
502 volumeslider.value = 0;
503 volumeChange();
504 } else {
505 volumeslider.value = savedVolumeValue;
506 volumeChange();
507 }
508 }
509
510 function toggleVolumeMute() {
511 muteVolume($('volumeslider').value != 0);
512 }
513
514 function getPathAndFilenameForPath(path) {
515 return path.match(/(.*)[\/\\]([^\/\\]+)\.\w+$/);
516 }
517
518
519 var hidingControlsAnimation = null;
520
521 const INACTIVITY_TIMEOUT = 5000;
522 const INACTIVITY_CHECK_INTERVAL = 1000;
523 const ANIMATION_DURATION = 1500;
524 const ANIMATION_STEP = 50;
525
526 function HidingControlsAnimation() {
527 this.offsetPercent = 0;
528 this.recentActivity = Date.now();
529
530 this.inactivityInterval = setInterval(this.checkInactivity.bind(this),
531 INACTIVITY_CHECK_INTERVAL);
532
533 this.onActivityClosure = this.onActivity.bind(this);
534 document.body.addEventListener('mousemove', this.onActivityClosure);
535 document.body.addEventListener('mousedown', this.onActivityClosure);
536 document.body.addEventListener('keydown', this.onActivityClosure);
537 }
538
539 HidingControlsAnimation.prototype = {
540
541 cleanup: function () {
542 this.stopAnimation();
543 clearInterval(this.inactivityInterval);
544 document.body.removeEventListener('mousemove', this.onActivityClosure);
545 document.body.removeEventListener('mousedown', this.onActivityClosure);
546 document.body.removeEventListener('keydown', this.onActivityClosure);
547 },
548
549 onActivity: function() {
550 this.recentActivity = Date.now();
551 // If not fully visible, start sliding up (or reverse sliding down).
552 if (this.offsetPercent != 0)
553 this.startAnimation(-1);
554 },
555
556 checkInactivity: function() {
557 if ((Date.now() - this.recentActivity) > INACTIVITY_TIMEOUT) {
558 // If fully visible start sliding down.
559 if (this.offsetPercent == 0)
560 this.startAnimation(1);
561 }
562 },
563
564 startAnimation: function (direction) {
565 this.direction = direction;
566 this.startOffset = this.offsetPercent;
567 this.startTime = Date.now();
568 if (!this.animationInterval)
569 this.animationInterval = setInterval(this.doAnimation.bind(this),
570 ANIMATION_STEP);
571 },
572
573 doAnimation: function () {
574 var phase = (Date.now() - this.startTime) / ANIMATION_DURATION;
575
576 var newOffsetPercent = this.startOffset + this.direction * phase * 100;
577
578 if (newOffsetPercent <= 0) {
579 this.offsetPercent = 0;
580 this.stopAnimation();
581 } else if (newOffsetPercent >= 100){
582 this.offsetPercent = 100;
583 this.stopAnimation();
584 } else {
585 this.offsetPercent = Math.round(newOffsetPercent);
586 }
587
588 $('playercontrols').style.top = this.offsetPercent + '%';
589 },
590
591 stopAnimation: function () {
592 if (this.animationInterval) {
593 clearInterval(this.animationInterval);
594 this.animationInterval = null;
595 }
596 }
597 };
598
599 function setupPlaybackControls() {
600 var element = $('playercontrols');
601 playercontrols.innerHTML = ''; // clear out other
602 var controlsclass = '';
603 if (hidingControlsAnimation) {
604 hidingControlsAnimation.cleanup();
605 hidingControlsAnimation = null;
606 }
607 if (videoPlaybackElement != null) {
608 controlsclass = 'video';
609 element.className = 'videocontrols';
610 hidingControlsAnimation = new HidingControlsAnimation();
611 } else if (audioPlaybackElement != null) {
612 controlsclass = 'audio';
613 element.className = 'audiocontrols';
614 }
615
616 var playbutton = document.createElement('div');
617 playbutton.id = 'playbutton';
618 playbutton.className = controlsclass + ' controlbutton playbutton';
619 playbutton.onclick = playPauseButtonClick;
620 var playicon = document.createElement('div');
621 playicon.className = 'icon playicon';
622 playbutton.appendChild(playicon);
623 element.appendChild(playbutton);
624
625
626 var pausebutton = document.createElement('div');
627 pausebutton.id = 'pausebutton';
628 pausebutton.className = controlsclass + ' controlbutton pausebutton';
629 pausebutton.onclick = playPauseButtonClick;
630 var pauseicon = document.createElement('div');
631 pauseicon.className = 'icon pauseicon';
632 pausebutton.appendChild(pauseicon);
633 element.appendChild(pausebutton);
634
635 var nextbutton = document.createElement('div');
636 nextbutton.id = 'nextbutton';
637 nextbutton.className = controlsclass + ' controlbutton nextbutton';
638 nextbutton.onclick = nextButtonClick;
639 var nexticon = document.createElement('div');
640 nexticon.className = 'icon nexticon';
641 nextbutton.appendChild(nexticon);
642 element.appendChild(nextbutton);
643
644 var prevbutton = document.createElement('div');
645 prevbutton.id = 'prevbutton';
646 prevbutton.className = controlsclass + ' controlbutton prevbutton';
647 prevbutton.onclick = prevButtonClick;
648 var previcon = document.createElement('div');
649 previcon.className = 'icon previcon';
650 prevbutton.appendChild(previcon);
651 element.appendChild(prevbutton);
652
653 var playlistbutton = document.createElement('div');
654 playlistbutton.id = 'playlistbutton';
655 playlistbutton.className = ' controlbutton playlistbutton';
656 playlistbutton.onclick = togglePlaylist;
657 var playlisticon = document.createElement('div');
658 playlisticon.className = 'icon playlisticon';
659 playlistbutton.appendChild(playlisticon);
660 element.appendChild(playlistbutton);
661
662 var slider = document.createElement('input');
663 slider.type = 'range';
664 slider.id = 'progress';
665 slider.className = controlsclass + ' progress';
666 slider.onchange = userChangedProgress;
667 element.appendChild(slider);
668
669 var sliderback = document.createElement('div');
670 sliderback.className = 'sliderback';
671 element.appendChild(sliderback);
672
673 var loaded = document.createElement('div');
674 loaded.id = 'sliderloaded';
675 loaded.className = 'sliderloaded';
676 sliderback.appendChild(loaded);
677
678 var played = document.createElement('div');
679 played.id = 'sliderplayed';
680 played.className = 'sliderplayed';
681 sliderback.appendChild(played);
682
683 var soundbutton = document.createElement('div');
684 soundbutton.id = 'soundbutton';
685 soundbutton.className = controlsclass + ' controlbutton soundbutton';
686 soundbutton.onclick = toggleVolumeMute;
687 soundbutton.onmouseover = showVolume;
688 soundbutton.onmouseout = hideVolume;
689 var soundicon = document.createElement('div');
690 soundicon.id = 'soundicon';
691 soundicon.className = 'icon soundiconhigh';
692 soundbutton.appendChild(soundicon);
693 element.appendChild(soundbutton);
694
695 var fullscreen = document.createElement('div');
696 fullscreen.id = 'fullscreen';
697 fullscreen.className = controlsclass + ' controlbutton fullscreen';
698 fullscreen.onclick = toggleFullscreen;
699 var fullscreenicon = document.createElement('div');
700 fullscreenicon.id = 'fullscreenicon';
701 fullscreenicon.className = 'icon fullscreenicon';
702 fullscreen.appendChild(fullscreenicon);
703 element.appendChild(fullscreen);
704
705 var volume = document.createElement('div');
706 volume.id = 'volume';
707 volume.className = controlsclass + ' volume';
708 volume.style.display = 'none';
709 volume.onmouseover = showVolume;
710 volume.onmouseout = hideVolume;
711 var volumeslider = document.createElement('input');
712 volumeslider.type = 'range';
713 volumeslider.id = 'volumeslider';
714 volumeslider.className = 'volumeslider';
715 volumeslider.onchange = volumeChange;
716 volume.appendChild(volumeslider);
717 document.body.appendChild(volume);
718 volumeChange();
719
720 var duration = document.createElement('div');
721 duration.id = 'duration';
722 duration.className = 'duration';
723 element.appendChild(duration);
724 }
725
726 function playAudioFile(uri) {
727 if (videoPlaybackElement != null) {
728 videoPlaybackElement.onerror = undefined;
729 document.body.removeChild(videoPlaybackElement);
730 videoPlaybackElement = null;
731 }
732 if (audioPlaybackElement == null) {
733 audioPlaybackElement = document.createElement('audio');
734 audioPlaybackElement.className = 'playbackaudioelement';
735 audioPlaybackElement.autoplay = true;
736 audioPlaybackElement.controls = false;
737 setupMediaEvents(audioPlaybackElement);
738 audioPlaybackElement.src = uri;
739 setupPlaybackControls();
740 document.body.appendChild(audioPlaybackElement);
741 var paths = getPathAndFilenameForPath(uri);
742 $('title').textContent = decodeURI(paths[2]);
743 } else {
744 setupMediaEvents(audioPlaybackElement);
745 audioPlaybackElement.src = uri;
746 audioPlaybackElement.load();
747 audioPlaybackElement.play();
748 var paths = getPathAndFilenameForPath(uri);
749 $('title').textContent = decodeURI(paths[2]);
750 }
751 }
752
753 function onkeydown(event) {
754 const ESCAPE_KEY_CODE = 27;
755 const SPACE_KEY_CODE = 32;
756 switch (event.keyCode) {
757 case ESCAPE_KEY_CODE:
758 if (fullScreen)
759 toggleFullscreen();
760 break;
761
762 case SPACE_KEY_CODE:
763 playPauseButtonClick();
764 break;
765 }
766 }
767
768 function toggleFullscreen() {
769 fullScreen = !fullScreen;
770 var fullscreenicon = $('fullscreenicon');
771 if (fullScreen) {
772 fullscreenicon.classList.remove('fullscreenicon');
773 fullscreenicon.classList.add('fullscreenexiticon');
774 }
775 else {
776 fullscreenicon.classList.remove('fullscreenexiticon');
777 fullscreenicon.classList.add('fullscreenicon');
778 }
779 chrome.send('toggleFullscreen', ['']);
780 }
781
782 function onMetadataAvail() {
783 var element = getMediaElement();
784 var duration = element.duration;
785 if (duration) {
786 var durString = '' + Math.floor((duration / 60)) + ':' + (Math.floor(duratio n) % 60);
787 var durDiv = $('duration');
788 durDiv.textContent = durString;
789 }
790 }
791
792 function playVideoFile(uri) {
793 if (audioPlaybackElement != null) {
794 document.body.removeChild(audioPlaybackElement);
795 audioPlaybackElement = null;
796 }
797 if (videoPlaybackElement == null) {
798 videoPlaybackElement = document.createElement('video');
799 videoPlaybackElement.className = 'playbackvideoelement';
800 videoPlaybackElement.autoplay = true;
801 videoPlaybackElement.controls = false;
802 setupMediaEvents(videoPlaybackElement);
803 videoPlaybackElement.src = uri;
804 videoPlaybackElement.load();
805 var toggleButton = document.createElement('div');
806 toggleButton.className = 'fullscreentoggle';
807 toggleButton.id = 'fullscreentoggle';
808 toggleButton.onclick = toggleFullscreen;
809 document.body.appendChild(toggleButton);
810 setupPlaybackControls();
811 document.body.appendChild(videoPlaybackElement);
812 } else {
813 setupMediaEvents(videoPlaybackElement);
814 videoPlaybackElement.src = uri;
815 videoPlaybackElement.load();
816 videoPlaybackElement.currentTime = 0;
817 videoPlaybackElement.play();
818 }
819 }
820
821 function stopAllPlayback() {
822 var element = getMediaElement();
823 if (element != null) {
824 element.pause();
825 }
826 }
827
828 function playlistChanged(info, playlist) {
829 if (info.force) {
830 currentPlaylist = playlist;
831 stopAllPlayback();
832 if (playlist.length >= 1) {
833 if (info.currentOffset) {
834 currentItem = info.currentOffset;
835 } else {
836 currentItem = 0;
837 }
838 var item = playlist[currentItem];
839 chrome.send('currentOffsetChanged', ['' + currentItem]);
840 playMediaFile(item.path);
841 }
842 } else {
843 var media = getMediaElement();
844 currentPlaylist = playlist;
845 // Only need to handle the case where we are not playing
846 // since if it is currently playing, it will just move
847 // to the next file when the current is complete.
848 if (media == null) {
849 for (var x = 0; x < playlist.length; x++) {
850 if (playlist[x].path == info.path) {
851 // found the newly added item.
852 currentItem = x;
853 chrome.send('currentOffsetChanged', ['' + currentItem]);
854 playMediaFile(playlist[x].path);
855 return;
856 }
857 }
858 if (playlist.length > 0) {
859 currentItem = 0;
860 chrome.send('currentOffsetChanged', ['' + currentItem]);
861 playMediaFile(playlist[0].path);
862 }
863 }
864 }
865 }
866
867 function togglePlaylist() {
868 chrome.send("togglePlaylist", []);
869 }
870
871 function playMediaFile(url) {
872 $('error').textContent = '';
873 console.log('playfile '+url);
874 $('title').textContent = '';
875 if (pathIsVideoFile(url) ) {
876 playVideoFile(url);
877 } else if(pathIsAudioFile(url)) {
878 playAudioFile(url);
879 } else {
880 alert('file unknown:' + url);
881 }
882 }
883
884 </script>
885 <body onload='load();' onselectstart='return false'>
886 <div id='error' class='error'></div>
887 <div id='title' class='audiotitle'></div>
888 <div id='glow' class='glow'></div>
889 <div class='playercontrolsbox'>
890 <div id='playercontrols'>
891 </div>
892 </div>
893 </body>
894 </html>
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/playlist.html ('k') | chrome/browser/resources/playlist.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698