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.ad) {
  65. this.controls.playPauseAd();
  66. if (this.ad.isLinear()) {
  67. return;
  68. }
  69. }
  70. this.controls.playPausePresentation();
  71. });
  72. if (this.ad) {
  73. // There was already an ad.
  74. this.updateAriaLabel();
  75. this.updateIcon();
  76. }
  77. }
  78. /**
  79. * @return {boolean}
  80. * @protected
  81. * @override
  82. */
  83. isPaused() {
  84. if (this.ad && this.ad.isLinear()) {
  85. return this.ad.isPaused();
  86. }
  87. return this.controls.presentationIsPaused();
  88. }
  89. /**
  90. * @return {boolean}
  91. * @protected
  92. * @override
  93. */
  94. isEnded() {
  95. if (this.ad && this.ad.isLinear()) {
  96. return false;
  97. }
  98. return this.player ? this.player.isEnded() : true;
  99. }
  100. /**
  101. * Called when the button's aria label needs to change.
  102. * To be overridden by subclasses.
  103. */
  104. updateAriaLabel() {}
  105. /**
  106. * Called when the button's icon needs to change.
  107. * To be overridden by subclasses.
  108. */
  109. updateIcon() {}
  110. };