fixed components; added playerapp example
This commit is contained in:
parent
5d71662617
commit
a9b12a231f
5 changed files with 99 additions and 6 deletions
42
examples/mediaplayer/mediaplayer.nim
Normal file
42
examples/mediaplayer/mediaplayer.nim
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
import karax, karaxdsl, vdom, components
|
||||
|
||||
const
|
||||
Play = 0
|
||||
Big = 1
|
||||
Small = 2
|
||||
Normal = 3
|
||||
|
||||
proc paused(n: Node): bool {.importcpp: "#.paused".}
|
||||
proc play(n: Node) {.importcpp.}
|
||||
proc pause(n: Node) {.importcpp.}
|
||||
proc `width=`(n: Node, w: int) {.importcpp: "#.width = #".}
|
||||
|
||||
proc mplayer*(id, resource: cstring): VNode {.component.} =
|
||||
proc handler(ev: Event; n: VNode) =
|
||||
let myVideo = document.getElementById(id)
|
||||
case n.key
|
||||
of Play:
|
||||
if myVideo.paused:
|
||||
myVideo.play()
|
||||
else:
|
||||
myVideo.pause()
|
||||
of Big: myVideo.width = 560
|
||||
of Small: myVideo.width = 320
|
||||
of Normal: myVideo.width = 420
|
||||
else: discard
|
||||
|
||||
result = buildHtml(tdiv):
|
||||
button(onclick=handler, key=Play):
|
||||
text "Play/Pause"
|
||||
button(onclick=handler, key=Big):
|
||||
text "Big"
|
||||
button(onclick=handler, key=Small):
|
||||
text "Small"
|
||||
button(onclick=handler, key=Normal):
|
||||
text "Normal"
|
||||
br()
|
||||
br()
|
||||
video(id=id, width="420"):
|
||||
source(src=resource, `type`="video/mp4"):
|
||||
text "Your browser does not support HTML5 video."
|
||||
Loading…
Add table
Add a link
Reference in a new issue