forked from HairyRabbit/Video
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideo.elm
More file actions
166 lines (139 loc) · 2.95 KB
/
Video.elm
File metadata and controls
166 lines (139 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
module Video.Video exposing (..)
import Html exposing (..)
import Html.Events exposing (..)
import Html.Attributes exposing (..)
import Html.App as App
import Time exposing(Time)
import Task exposing (Task)
import Debug
import Slider.Slider as Slider
type State
= Pause
| Playing
type Direction
= Prev
| Next
type alias Model =
{ slider : Slider.Model
--, beginAt : Time
--, during : Time
, state : State
, speed : Int
--, fps : Float
--, frames : List a
--, curr : Int
}
initModel : Model
initModel =
{ slider = Slider.initModel
, state = Pause
, speed = 8
}
type Msg
= NoOp
| MsgSlider Slider.Msg
| ToggleState
| ToggleDoneState Time
| JumpFrame (Maybe Int) (Maybe Direction)
| Tick Time
init : (Model, Cmd Msg)
init =
let
(mSlider, fxSlider) =
Slider.init
fx =
Cmd.batch
[ Cmd.map MsgSlider fxSlider
]
in
(initModel, fx)
-- UPDATE
update : Msg -> Model -> (Model, Cmd Msg)
update msg ({ state } as model) =
case msg of
MsgSlider msgSlider ->
let
(m, fx) =
Slider.update msgSlider model.slider
in
( { model | slider = m }
, Cmd.map MsgSlider fx
)
ToggleState ->
let
turnState =
case state of
Pause ->
Playing
Playing ->
Pause
fx =
Task.perform (\_ -> NoOp) ToggleDoneState Time.now
in
( { model | state = turnState }
, fx
)
ToggleDoneState t ->
let
_ =
Debug.log "time" t
in
(model, Cmd.none)
Tick t ->
let
_ =
Debug.log "tt" t
in
(model, Cmd.none)
_ ->
(model, Cmd.none)
-- SUBSCRIPTIONS
subscriptions : Model -> Sub Msg
subscriptions model =
let
fxTimer =
case model.state of
Pause ->
Sub.none
Playing ->
Time.every (Time.second / (toFloat model.speed)) Tick
in
Sub.batch
[ Sub.map MsgSlider (Slider.subscriptions model.slider)
, fxTimer
]
-- VIEW
view : Model -> Html Msg
view ({ state } as model) =
let
playStateView =
case state of
Pause ->
text "||"
Playing ->
text "|>"
controlView =
div [ class "video-control row" ]
[ div [ class "video-btn-group grid width--4" ]
[ button [ class "video-btn" ] [ text "<<" ]
, button [ class "video-btn video-btn--lg"
, onClick ToggleState
]
[ playStateView ]
, button [ class "video-btn" ] [ text ">>" ]
]
, div [ class "video-slider grid width--8" ]
[ App.map MsgSlider <| Slider.view model.slider
]
]
screenView =
div [ class "video-screen"]
[
]
view' =
div [ class "video" ]
[ screenView
, controlView
]
in
view'