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

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: Fixed style errors and localized strings. Created 9 years, 7 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 -webkit-transform: translateZ(0);
12 }
13
14 .error {
15 left: 0;
16 right: 0;
17 color: white;
18 bottom: 38px;
19 position: absolute;
20 }
21
22 .glow {
23 left: 0;
24 right: 0;
25 bottom: 30px;
26 height: 8px;
27 opacity: .4;
28 position: absolute;
29 background: -webkit-linear-gradient(transparent, white);
30 }
31
32 .audiotitle {
33 left: 0;
34 right: 0;
35 text-align: center;
36 position: absolute;
37 color: white;
38 top: 100px;
39 }
40
41 .progress {
42 -webkit-appearance: sliderthumb-horizontal;
43 position: absolute;
44 background: transparent;
45 left: 93px;
46 right: 120px;
47 bottom: -2px;
48 height: 30px;
49 z-index: 99999;
50 border-left: 1px solid #424242;
51 }
52
53 .playercontrolsbox {
54 bottom: 0;
55 left: 0;
56 height: 30px;
57 right: 0;
58 position: absolute;
59 }
60
61 .videocontrols {
62 top: 0;
63 left: 0;
64 z-index: 999;
65 height: 100%;
66 opacity: .9;
67 right: 0;
68 position: absolute;
69 background: -webkit-linear-gradient(#323232, #070707);
70 }
71
72 .sliderback {
73 bottom: 12px;
74 left: 93px;
75 right: 120px;
76 height: 5px;
77 position: absolute;
78 border-radius: 3px;
79 background: -webkit-linear-gradient(#ced9fa, #e8ecf9);
80 border: 1px solid #ffffff;
81 }
82
83 .sliderplayed {
84 height: 100%;
85 width:0;
86 left: -1px;
87 top: -1px;
88 border-radius: 3px;
89 border: 1px solid #9ca5b7;
90 position: absolute;
91 background: -webkit-linear-gradient(#4a5d84, #232c3d);
92 }
93
94 .sliderloaded {
95 height: 100%;
96 width:0;
97 left: -1px;
98 top: -1px;
99 border-radius: 3px;
100 position: absolute;
101 background: #6a799a;
102 border: 1px solid #ffffff;
103 }
104
105 .audiocontrols {
106 top: 0;
107 left: 0;
108 z-index: 999;
109 height: 100%;
110 opacity: .9;
111 right: 0;
112 position: absolute;
113 background: -webkit-linear-gradient(#323232, #070707);
114 }
115
116 .soundbutton {
117 position: absolute;
118 right: 30px;
119 bottom: 0;
120 border-left: 1px solid #424242;
121 border-right: 1px solid black;
122 }
123
124 .soundiconhigh {
125 background: url('shared/images/mediaplayer_vol_high.png');
126 }
127
128 .soundiconmuted {
129 background: url('shared/images/mediaplayer_vol_mute.png');
130 }
131
132 .soundiconhigh,
133 .soundiconmuted {
134 background-repeat: no-repeat;
135 background-position: 6px 8px;
136 }
137
138 .volume {
139 position: absolute;
140 bottom: 30px;
141 height: 80px;
142 width: 30px;
143 right: 30px;
144 z-index: 99999;
145 background: black;
146 background: -webkit-linear-gradient(#323232, #070707);
147 }
148
149 .fullscreen {
150 position: absolute;
151 right: 60px;
152 bottom: 0;
153 border-left: 1px solid #424242;
154 border-right: 1px solid black;
155 }
156
157 .fullscreenicon {
158 background: url('shared/images/mediaplayer_full_screen.png');
159 background-repeat: no-repeat;
160 background-position: 6px 8px;
161 }
162
163 .fullscreenexiticon {
164 background: url('shared/images/mediaplayer_full_screen_exit.png');
165 background-repeat: no-repeat;
166 background-position: 6px 8px;
167 }
168
169 .volumeslider {
170 -webkit-appearance: slider-vertical;
171 position: absolute;
172 left: 0;
173 right: 0;
174 bottom: 0;
175 top: 0;
176 }
177
178 .playbutton {
179 position: absolute;
180 left: 30px;
181 bottom: 0;
182 border-left: 1px solid #424242;
183 border-right: 1px solid black;
184 }
185
186 .playicon {
187 background: url('shared/images/mediaplayer_play.png');
188 background-repeat: no-repeat;
189 background-position: 9px 8px;
190 }
191
192 .pausebutton {
193 position: absolute;
194 left: 30px;
195 bottom: 0;
196 border-left: 1px solid #424242;
197 border-right: 1px solid black;
198 }
199
200 .pauseicon {
201 background: url('shared/images/mediaplayer_pause.png');
202 background-repeat: no-repeat;
203 background-position: 9px 8px;
204 }
205
206 .prevbutton {
207 position: absolute;
208 left: 0;
209 bottom: 0;
210 border-right: 1px solid black;
211 }
212
213 .previcon {
214 background: url('shared/images/mediaplayer_prev.png');
215 background-repeat: no-repeat;
216 background-position: 6px 8px;
217 }
218
219 .playbackvideoelement {
220 width: 100%;
221 height: 100%;
222 position: absolute;
223 left: 0;
224 top: 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: url('shared/images/mediaplayer_next.png');
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: url('shared/images/mediaplayer_playlist.png');
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

Powered by Google App Engine
This is Rietveld 408576698