java - 如何定义方法: play() and pause() in Vaadin video

标签 java vaadin

我在我的 vaadin 应用程序中创建了一个用 @tag('video') 注释的自定义类。 所需的属性(如海报、控件、自动播放、src、宽度等)已定义,并且一切正常。 现在我需要为该类定义 play() 和pause() 方法,以便我可以以编程方式使用它们。

注意:该类充当视频,就像在 html 中一样。

@Tag("video")
public class Video extends Component implements ClickNotifier{

protected String getVideoSourceAttributeName() {
return VideoAttributes.Source;
}

public void setWidth(String width) {
this.getElement().setAttribute(VideoAttributes.Width, width);
}

public void setHeight(String height) {
this.getElement().setAttribute(VideoAttributes.Height, height);
}

private interface VideoAttributes {
    String Controls = "controls";
    String Source = "src";
    String CurrentTime = "currentTime";
    String AutoPlay = "autoplay";
    String Loop = "loop";
    String Preload = "preload";
    String Poster = "poster";
    String Width = "width";
    String Height = "height";
}


public interface functions {

}

}

最佳答案

在播放和暂停的情况下,DOM元素上有相应的方法(继承于 HTMLMediaElement )。您可以使用 callJsFunction 方法直接从服务器端 Element API 调用此类方法,例如getElement().callJsFunction("play")

关于java - 如何定义方法: play() and pause() in Vaadin video,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76131470/

相关文章:

java - 如何从 Google Map v2 的 View 中获取 fragment

java - Guava Cache的读锁是否免费

java - Magnolia v6.2 Atmosphere 无法配置 JSR-356

java - 自定义 Vaadin Flow Grid 组件的选择列标题

java - 我怎样才能让它在不卡住 GUI 的情况下运行

java - DynamicJasper 将列添加到具有不支持的数据类型的 fastreportbuilder

java - 我可以在同一包下的另一个类中调用一个类的静态方法吗?

java - 如何在 Vaadin 10 中管理 session ?

java - 从布局中删除组件失败

javafx - JavaFX 和 Vaadin 的区别