You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VMediaBase.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui;
  17. import com.google.gwt.dom.client.Document;
  18. import com.google.gwt.dom.client.Element;
  19. import com.google.gwt.dom.client.MediaElement;
  20. import com.google.gwt.dom.client.NodeList;
  21. import com.google.gwt.dom.client.SourceElement;
  22. import com.google.gwt.dom.client.Text;
  23. import com.google.gwt.user.client.ui.Widget;
  24. public abstract class VMediaBase extends Widget {
  25. private MediaElement media;
  26. private Text altText;
  27. /**
  28. * Sets the MediaElement that is to receive all commands and properties.
  29. *
  30. * @param element
  31. */
  32. public void setMediaElement(MediaElement element) {
  33. setElement(element);
  34. media = element;
  35. }
  36. public void play() {
  37. media.play();
  38. }
  39. public void pause() {
  40. media.pause();
  41. }
  42. public void setAltText(String alt) {
  43. if (altText == null) {
  44. altText = Document.get().createTextNode(alt);
  45. media.appendChild(altText);
  46. } else {
  47. altText.setNodeValue(alt);
  48. }
  49. }
  50. public void setControls(boolean shouldShowControls) {
  51. media.setControls(shouldShowControls);
  52. }
  53. public void setAutoplay(boolean shouldAutoplay) {
  54. media.setAutoplay(shouldAutoplay);
  55. }
  56. public void setMuted(boolean mediaMuted) {
  57. media.setMuted(mediaMuted);
  58. }
  59. /**
  60. * Sets the preload attribute that is intended to provide a hint to the
  61. * browser how the media should be preloaded. See
  62. * AbstractMedia.setPreload(PreloadMode) and PreloadMode for more
  63. * information.
  64. *
  65. * @param preload
  66. * preload mode
  67. * @since 7.7.11
  68. */
  69. public void setPreload(final String preload) {
  70. media.setPreload(preload);
  71. }
  72. /**
  73. * Enables or disables looping.
  74. *
  75. * @param loop
  76. * if true, enable looping
  77. * @since 7.7.11
  78. */
  79. public void setLoop(final boolean loop) {
  80. media.setLoop(loop);
  81. }
  82. public void removeAllSources() {
  83. NodeList<com.google.gwt.dom.client.Element> l = media
  84. .getElementsByTagName(SourceElement.TAG);
  85. for (int i = l.getLength() - 1; i >= 0; i--) {
  86. media.removeChild(l.getItem(i));
  87. }
  88. }
  89. public void load() {
  90. media.load();
  91. }
  92. public void addSource(String sourceUrl, String sourceType) {
  93. Element src = Document.get().createElement(SourceElement.TAG);
  94. src.setAttribute("src", sourceUrl);
  95. src.setAttribute("type", sourceType);
  96. media.appendChild(src);
  97. }
  98. }