我在我的 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/