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.

Video.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright 2000-2016 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.ui;
  17. import java.util.Collection;
  18. import org.jsoup.nodes.Attributes;
  19. import org.jsoup.nodes.Element;
  20. import org.jsoup.select.Elements;
  21. import com.vaadin.server.Resource;
  22. import com.vaadin.shared.ui.video.VideoConstants;
  23. import com.vaadin.shared.ui.video.VideoState;
  24. import com.vaadin.ui.declarative.DesignAttributeHandler;
  25. import com.vaadin.ui.declarative.DesignContext;
  26. /**
  27. * The Video component translates into an HTML5 <video> element and as
  28. * such is only supported in browsers that support HTML5 media markup. Browsers
  29. * that do not support HTML5 display the text or HTML set by calling
  30. * {@link #setAltText(String)}.
  31. *
  32. * A flash-player fallback can be implemented by setting HTML content allowed (
  33. * {@link #setHtmlContentAllowed(boolean)} and calling
  34. * {@link #setAltText(String)} with the flash player markup. An example of flash
  35. * fallback can be found at the <a href=
  36. * "https://developer.mozilla.org/En/Using_audio_and_video_in_Firefox#Using_Flash"
  37. * >Mozilla Developer Network</a>.
  38. *
  39. * Multiple sources can be specified. Which of the sources is used is selected
  40. * by the browser depending on which file formats it supports. See
  41. * <a href="http://en.wikipedia.org/wiki/HTML5_video#Table">wikipedia</a> for a
  42. * table of formats supported by different browsers.
  43. *
  44. * @author Vaadin Ltd
  45. * @since 6.7.0
  46. */
  47. public class Video extends AbstractMedia {
  48. @Override
  49. protected VideoState getState() {
  50. return (VideoState) super.getState();
  51. }
  52. public Video() {
  53. this("", null);
  54. }
  55. /**
  56. * @param caption
  57. * The caption for this video.
  58. */
  59. public Video(String caption) {
  60. this(caption, null);
  61. }
  62. /**
  63. * @param caption
  64. * The caption for this video.
  65. * @param source
  66. * The Resource containing the video to play.
  67. */
  68. public Video(String caption, Resource source) {
  69. setCaption(caption);
  70. setSource(source);
  71. setShowControls(true);
  72. }
  73. /**
  74. * Sets the poster image, which is shown in place of the video before the
  75. * user presses play.
  76. *
  77. * @param poster
  78. */
  79. public void setPoster(Resource poster) {
  80. setResource(VideoConstants.POSTER_RESOURCE, poster);
  81. }
  82. /**
  83. * @return The poster image.
  84. */
  85. public Resource getPoster() {
  86. return getResource(VideoConstants.POSTER_RESOURCE);
  87. }
  88. @Override
  89. public void readDesign(Element design, DesignContext designContext) {
  90. Elements elems = design.getElementsByTag("poster");
  91. for (Element poster : elems) {
  92. if (getPoster() == null && poster.hasAttr("href")) {
  93. setPoster(DesignAttributeHandler.readAttribute("href",
  94. poster.attributes(), Resource.class));
  95. }
  96. poster.remove();
  97. }
  98. // Poster is extracted so AbstractMedia does not include it in alt text
  99. super.readDesign(design, designContext);
  100. }
  101. @Override
  102. public void writeDesign(Element design, DesignContext designContext) {
  103. super.writeDesign(design, designContext);
  104. if (getPoster() != null) {
  105. Attributes attr = design.appendElement("poster").attributes();
  106. DesignAttributeHandler.writeAttribute("href", attr, getPoster(),
  107. null, Resource.class);
  108. }
  109. }
  110. @Override
  111. protected Collection<String> getCustomAttributes() {
  112. Collection<String> result = super.getCustomAttributes();
  113. result.add("poster");
  114. return result;
  115. }
  116. }