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