Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

VMediaBase.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2000-2013 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.MediaElement;
  19. import com.google.gwt.dom.client.NodeList;
  20. import com.google.gwt.dom.client.SourceElement;
  21. import com.google.gwt.dom.client.Text;
  22. import com.google.gwt.user.client.ui.Widget;
  23. public abstract class VMediaBase extends Widget {
  24. private MediaElement media;
  25. private Text altText;
  26. /**
  27. * Sets the MediaElement that is to receive all commands and properties.
  28. *
  29. * @param element
  30. */
  31. public void setMediaElement(MediaElement element) {
  32. setElement(element);
  33. media = element;
  34. }
  35. public void play() {
  36. media.play();
  37. }
  38. public void pause() {
  39. media.pause();
  40. }
  41. public void setAltText(String alt) {
  42. if (altText == null) {
  43. altText = Document.get().createTextNode(alt);
  44. media.appendChild(altText);
  45. } else {
  46. altText.setNodeValue(alt);
  47. }
  48. }
  49. public void setControls(boolean shouldShowControls) {
  50. media.setControls(shouldShowControls);
  51. }
  52. public void setAutoplay(boolean shouldAutoplay) {
  53. media.setAutoplay(shouldAutoplay);
  54. }
  55. public void setMuted(boolean mediaMuted) {
  56. media.setMuted(mediaMuted);
  57. }
  58. public void removeAllSources() {
  59. NodeList<com.google.gwt.dom.client.Element> l = media
  60. .getElementsByTagName(SourceElement.TAG);
  61. for (int i = l.getLength() - 1; i >= 0; i--) {
  62. media.removeChild(l.getItem(i));
  63. }
  64. }
  65. public void load() {
  66. media.load();
  67. }
  68. public void addSource(String sourceUrl, String sourceType) {
  69. com.google.gwt.user.client.Element src = Document.get()
  70. .createElement(SourceElement.TAG).cast();
  71. src.setAttribute("src", sourceUrl);
  72. src.setAttribute("type", sourceType);
  73. media.appendChild(src);
  74. }
  75. }