Skip to content
This repository was archived by the owner on Sep 26, 2020. It is now read-only.

Commit 423bbd8

Browse files
authored
Add video component (#150)
* Add video component * Accept file instead of source & add controls property
1 parent 18f80e9 commit 423bbd8

File tree

1 file changed

+46
-0
lines changed
  • ui-vaadin/src/main/kotlin/edu/wpi/axon/ui/component

1 file changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package edu.wpi.axon.ui.component
2+
3+
import com.github.mvysny.karibudsl.v10.VaadinDsl
4+
import com.github.mvysny.karibudsl.v10.init
5+
import com.vaadin.flow.component.Component
6+
import com.vaadin.flow.component.HasComponents
7+
import com.vaadin.flow.component.HasSize
8+
import com.vaadin.flow.component.HasStyle
9+
import com.vaadin.flow.component.Tag
10+
import com.vaadin.flow.dom.Element
11+
import com.vaadin.flow.server.InputStreamFactory
12+
import com.vaadin.flow.server.StreamResource
13+
import java.io.File
14+
import java.io.FileInputStream
15+
16+
@Tag("video")
17+
class Video(file: File) : Component(), HasSize, HasStyle {
18+
private class Source(file: File) : Element("source") {
19+
init {
20+
setAttribute("src", StreamResource(file.name, InputStreamFactory { FileInputStream(file) }))
21+
}
22+
}
23+
24+
var controls: Boolean
25+
get() = element.hasAttribute("controls")
26+
set(value) {
27+
if (value) {
28+
element.setAttribute("controls", "")
29+
} else {
30+
element.removeAttribute("controls")
31+
}
32+
}
33+
34+
var volume: Double
35+
get() = element.getProperty("volume", 0.0)
36+
set(value) { element.setProperty("volume", value) }
37+
38+
init {
39+
controls = true
40+
41+
element.appendChild(Source(file))
42+
}
43+
}
44+
45+
@VaadinDsl
46+
fun (@VaadinDsl HasComponents).video(file: File, block: (@VaadinDsl Video).() -> Unit = {}) = init(Video(file), block)

0 commit comments

Comments
 (0)