Source: ui/play_button.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.ui.PlayButton');
  7. goog.require('shaka.ads.Utils');
  8. goog.require('shaka.ui.Element');
  9. goog.require('shaka.ui.Localization');
  10. goog.require('shaka.util.Dom');
  11. goog.requireType('shaka.ui.Controls');
  12. /**
  13. * @extends {shaka.ui.Element}
  14. * @implements {shaka.extern.IUIPlayButton}
  15. * @export
  16. */
  17. shaka.ui.PlayButton = class extends shaka.ui.Element {
  18. /**
  19. * @param {!HTMLElement} parent
  20. * @param {!shaka.ui.Controls} controls
  21. */
  22. constructor(parent, controls) {
  23. super(parent, controls);
  24. /** @protected {!HTMLButtonElement} */
  25. this.button = shaka.util.Dom.createButton();
  26. this.parent.appendChild(this.button);
  27. const LOCALE_UPDATED = shaka.ui.Localization.LOCALE_UPDATED;
  28. this.eventManager.listen(this.localization, LOCALE_UPDATED, () => {
  29. this.updateAriaLabel();
  30. });
  31. const LOCALE_CHANGED = shaka.ui.Localization.LOCALE_CHANGED;
  32. this.eventManager.listen(this.localization, LOCALE_CHANGED, () => {
  33. this.updateAriaLabel();
  34. });
  35. this.eventManager.listen(this.video, 'play', () => {
  36. this.updateAriaLabel();
  37. this.updateIcon();
  38. });
  39. this.eventManager.listen(this.video, 'pause', () => {
  40. this.updateAriaLabel();
  41. this.updateIcon();
  42. });
  43. this.eventManager.listen(this.video, 'seeking', () => {
  44. this.updateAriaLabel();
  45. this.updateIcon();
  46. });
  47. this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_PAUSED, () => {
  48. this.updateAriaLabel();
  49. this.updateIcon();
  50. });
  51. this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_RESUMED, () => {
  52. this.updateAriaLabel();
  53. this.updateIcon();
  54. });
  55. this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_STARTED, () => {
  56. this.updateAriaLabel();
  57. this.updateIcon();
  58. });
  59. this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_STOPPED, () => {
  60. this.updateAriaLabel();
  61. this.updateIcon();
  62. });
  63. this.eventManager.listen(this.button, 'click', () => {
  64. if (!this.controls.isOpaque()) {
  65. return;
  66. }
  67. this.controls.playPausePresentation();
  68. });
  69. if (this.ad) {
  70. // There was already an ad.
  71. this.updateAriaLabel();
  72. this.updateIcon();
  73. }
  74. }
  75. /**
  76. * @return {boolean}
  77. * @protected
  78. * @override
  79. */
  80. isPaused() {
  81. if (this.ad && this.ad.isLinear()) {
  82. return this.ad.isPaused();
  83. }
  84. return this.controls.presentationIsPaused();
  85. }
  86. /**
  87. * @return {boolean}
  88. * @protected
  89. * @override
  90. */
  91. isEnded() {
  92. if (this.ad && this.ad.isLinear()) {
  93. return false;
  94. }
  95. return this.player ? this.player.isEnded() : true;
  96. }
  97. /**
  98. * Called when the button's aria label needs to change.
  99. * To be overridden by subclasses.
  100. */
  101. updateAriaLabel() {}
  102. /**
  103. * Called when the button's icon needs to change.
  104. * To be overridden by subclasses.
  105. */
  106. updateIcon() {}
  107. };