YTPlayerView-iframe-player.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!--
  2. Copyright 2014 Google Inc. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. -->
  13. <!DOCTYPE html>
  14. <html>
  15. <head>
  16. <style>
  17. body { margin: 0; width:100%%; height:100%%; background-color:#000000; }
  18. html { width:100%%; height:100%%; background-color:#000000; }
  19. .embed-container iframe,
  20. .embed-container object,
  21. .embed-container embed {
  22. position: absolute;
  23. top: 0;
  24. left: 0;
  25. width: 100%% !important;
  26. height: 100%% !important;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div class="embed-container">
  32. <div id="player"></div>
  33. </div>
  34. <script src="https://www.youtube.com/iframe_api" onerror="window.location.href='ytplayer://onYouTubeIframeAPIFailedToLoad'"></script>
  35. <script>
  36. var player;
  37. var error = false;
  38. YT.ready(function() {
  39. player = new YT.Player('player', %@);
  40. player.setSize(window.innerWidth, window.innerHeight);
  41. window.location.href = 'ytplayer://onYouTubeIframeAPIReady';
  42. // this will transmit playTime frequently while playng
  43. function getCurrentTime() {
  44. var state = player.getPlayerState();
  45. if (state == YT.PlayerState.PLAYING) {
  46. time = player.getCurrentTime()
  47. window.location.href = 'ytplayer://onPlayTime?data=' + time;
  48. }
  49. }
  50. window.setInterval(getCurrentTime, 500);
  51. });
  52. function onReady(event) {
  53. window.location.href = 'ytplayer://onReady?data=' + event.data;
  54. }
  55. function onStateChange(event) {
  56. if (!error) {
  57. window.location.href = 'ytplayer://onStateChange?data=' + event.data;
  58. }
  59. else {
  60. error = false;
  61. }
  62. }
  63. function onPlaybackQualityChange(event) {
  64. window.location.href = 'ytplayer://onPlaybackQualityChange?data=' + event.data;
  65. }
  66. function onPlayerError(event) {
  67. if (event.data == 100) {
  68. error = true;
  69. }
  70. window.location.href = 'ytplayer://onError?data=' + event.data;
  71. }
  72. window.onresize = function() {
  73. player.setSize(window.innerWidth, window.innerHeight);
  74. }
  75. </script>
  76. </body>
  77. </html>