Skip to content

Commit 9f63d79

Browse files
committed
Merge pull request #164 from ocsigen/audio
Lib: complete audio/videoElement
2 parents 601d20b + 60577b6 commit 9f63d79

File tree

2 files changed

+104
-4
lines changed

2 files changed

+104
-4
lines changed

lib/dom_html.ml

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,14 +814,56 @@ class type tableElement = object
814814
method deleteRow : int -> unit meth
815815
end
816816

817+
class type timeRanges = object
818+
method length : int readonly_prop
819+
method start : int -> float meth
820+
method end_ : int -> float meth
821+
end
822+
823+
type networkState =
824+
| NETWORK_EMPTY
825+
| NETWORK_IDLE
826+
| NETWORK_LOADING
827+
| NETWORK_NO_SOURCE
817828

829+
type readyState =
830+
| HAVE_NOTHING
831+
| HAVE_METADATA
832+
| HAVE_CURRENT_DATA
833+
| HAVE_FUTURE_DATA
834+
| HAVE_ENOUGH_DATA
835+
836+
(* http://www.w3schools.com/tags/ref_av_dom.asp *)
837+
(* only features supported by all browser. (IE9+) *)
818838
class type mediaElement = object
819839
inherit element
820-
method currentTime : float prop
821-
method duration : float prop
840+
method canPlayType : js_string t -> js_string t meth
841+
method load : unit meth
822842
method play : unit meth
823843
method pause : unit meth
824844

845+
method autoplay : bool t prop
846+
method buffered : timeRanges t readonly_prop
847+
method controls : bool t prop
848+
method currentSrc : js_string t readonly_prop
849+
method currentTime : float prop
850+
method duration : float readonly_prop
851+
method ended : bool t readonly_prop
852+
method loop : bool t prop
853+
method mediagroup : js_string t prop
854+
method muted : bool t prop
855+
method networkState_int : int readonly_prop
856+
method networkState : networkState readonly_prop
857+
method paused : bool t readonly_prop
858+
method playbackRate : float prop
859+
method played : timeRanges t readonly_prop
860+
method preload : js_string t prop
861+
method readyState_int : int readonly_prop
862+
method readyState : readyState readonly_prop
863+
method seekable : timeRanges t readonly_prop
864+
method seeking : bool t readonly_prop
865+
method src : js_string t prop
866+
method volume : float prop
825867
end
826868

827869
class type audioElement = object
@@ -1296,6 +1338,8 @@ let createAddress doc = createElement doc "address"
12961338
let createFrameset doc : frameSetElement t = unsafeCreateElement doc "frameset"
12971339
let createFrame doc : frameElement t = unsafeCreateElement doc "frame"
12981340
let createIframe doc : iFrameElement t = unsafeCreateElement doc "iframe"
1341+
let createAudio doc : audioElement t = unsafeCreateElement doc "audio"
1342+
let createVideo doc : audioElement t = unsafeCreateElement doc "video"
12991343

13001344
exception Canvas_not_available
13011345

@@ -1385,6 +1429,8 @@ module CoerceTo = struct
13851429
let title e = unsafeCoerce "title" e
13861430
let tr e = unsafeCoerce "tr" e
13871431
let ul e = unsafeCoerce "ul" e
1432+
let audio e = unsafeCoerce "audio" e
1433+
let video e = unsafeCoerce "video" e
13881434

13891435
let unsafeCoerceEvent constr (ev : #event t) =
13901436
if def constr != undefined && Js.instanceof ev constr then
@@ -1478,6 +1524,7 @@ let element : #Dom.element t -> element t = Js.Unsafe.coerce
14781524
type taggedElement =
14791525
| A of anchorElement t
14801526
| Area of areaElement t
1527+
| Audio of audioElement t
14811528
| Base of baseElement t
14821529
| Blockquote of quoteElement t
14831530
| Body of bodyElement t
@@ -1535,6 +1582,7 @@ type taggedElement =
15351582
| Title of titleElement t
15361583
| Tr of tableRowElement t
15371584
| Ul of uListElement t
1585+
| Video of videoElement t
15381586
| Other of element t
15391587

15401588
let other e = Other (e : #element t :> element t)
@@ -1549,6 +1597,7 @@ let tagged (e : #element t) =
15491597
begin match tag with
15501598
| "a" -> A (Js.Unsafe.coerce e)
15511599
| "area" -> Area (Js.Unsafe.coerce e)
1600+
| "audio" -> Audio (Js.Unsafe.coerce e)
15521601
| _ -> other e
15531602
end
15541603
| 'b' ->
@@ -1668,6 +1717,11 @@ let tagged (e : #element t) =
16681717
| "ul" -> Ul (Js.Unsafe.coerce e)
16691718
| _ -> other e
16701719
end
1720+
| 'v' ->
1721+
begin match tag with
1722+
| "video" -> Video (Js.Unsafe.coerce e)
1723+
| _ -> other e
1724+
end
16711725
| _ ->
16721726
other e
16731727

lib/dom_html.mli

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,14 +763,54 @@ class type tableElement = object
763763
method deleteRow : int -> unit meth
764764
end
765765

766+
class type timeRanges = object
767+
method length : int readonly_prop
768+
method start : int -> float meth
769+
method end_ : int -> float meth
770+
end
771+
772+
type networkState =
773+
| NETWORK_EMPTY
774+
| NETWORK_IDLE
775+
| NETWORK_LOADING
776+
| NETWORK_NO_SOURCE
777+
778+
type readyState =
779+
| HAVE_NOTHING
780+
| HAVE_METADATA
781+
| HAVE_CURRENT_DATA
782+
| HAVE_FUTURE_DATA
783+
| HAVE_ENOUGH_DATA
766784

767785
class type mediaElement = object
768786
inherit element
769-
method currentTime : float prop
770-
method duration : float prop
787+
method canPlayType : js_string t -> js_string t meth
788+
method load : unit meth
771789
method play : unit meth
772790
method pause : unit meth
773791

792+
method autoplay : bool t prop
793+
method buffered : timeRanges t readonly_prop
794+
method controls : bool t prop
795+
method currentSrc : js_string t readonly_prop
796+
method currentTime : float prop
797+
method duration : float readonly_prop
798+
method ended : bool t readonly_prop
799+
method loop : bool t prop
800+
method mediagroup : js_string t prop
801+
method muted : bool t prop
802+
method networkState_int : int readonly_prop
803+
method networkState : networkState readonly_prop
804+
method paused : bool t readonly_prop
805+
method playbackRate : float prop
806+
method played : timeRanges t readonly_prop
807+
method preload : js_string t prop
808+
method readyState_int : int readonly_prop
809+
method readyState : readyState readonly_prop
810+
method seekable : timeRanges t readonly_prop
811+
method seeking : bool t readonly_prop
812+
method src : js_string t prop
813+
method volume : float prop
774814
end
775815

776816
class type audioElement = object
@@ -1335,6 +1375,8 @@ val createAddress : document t -> element t
13351375
val createFrameset : document t -> frameSetElement t
13361376
val createFrame : document t -> frameElement t
13371377
val createIframe : document t -> iFrameElement t
1378+
val createAudio : document t -> audioElement t
1379+
val createVideo : document t -> videoElement t
13381380

13391381
exception Canvas_not_available
13401382
val createCanvas : document t -> canvasElement t
@@ -1352,6 +1394,7 @@ val element : #Dom.element t -> element t
13521394
type taggedElement =
13531395
| A of anchorElement t
13541396
| Area of areaElement t
1397+
| Audio of audioElement t
13551398
| Base of baseElement t
13561399
| Blockquote of quoteElement t
13571400
| Body of bodyElement t
@@ -1409,6 +1452,7 @@ type taggedElement =
14091452
| Title of titleElement t
14101453
| Tr of tableRowElement t
14111454
| Ul of uListElement t
1455+
| Video of videoElement t
14121456
| Other of element t
14131457

14141458
val tagged : #element t -> taggedElement
@@ -1437,6 +1481,7 @@ module CoerceTo : sig
14371481

14381482
val a : #element t -> anchorElement t opt
14391483
val area : #element t -> areaElement t opt
1484+
val audio : #element t -> audioElement t opt
14401485
val base : #element t -> baseElement t opt
14411486
val blockquote : #element t -> quoteElement t opt
14421487
val body : #element t -> bodyElement t opt
@@ -1494,6 +1539,7 @@ module CoerceTo : sig
14941539
val title : #element t -> titleElement t opt
14951540
val tr : #element t -> tableRowElement t opt
14961541
val ul : #element t -> uListElement t opt
1542+
val video : #element t -> videoElement t opt
14971543

14981544
(** Event *)
14991545

0 commit comments

Comments
 (0)