Clean, adds fullscreen button
This commit is contained in:
parent
e2df6c1881
commit
2f1cc48b0b
14
index.html
14
index.html
|
@ -25,6 +25,12 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(HTMLElement.prototype, "document", {
|
||||||
|
get: function() {
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var app = Elm.Main.init({
|
var app = Elm.Main.init({
|
||||||
node: document.getElementById('container'),
|
node: document.getElementById('container'),
|
||||||
});
|
});
|
||||||
|
@ -81,6 +87,14 @@
|
||||||
const video = document.getElementById('video');
|
const video = document.getElementById('video');
|
||||||
video.currentTime = arg;
|
video.currentTime = arg;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.ports.requestFullscreen.subscribe(function() {
|
||||||
|
document.getElementById('full').requestFullscreen();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.ports.exitFullscreen.subscribe(function() {
|
||||||
|
document.exitFullscreen();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
78
src/Main.elm
78
src/Main.elm
|
@ -34,6 +34,7 @@ type alias Model =
|
||||||
, loaded : List ( Float, Float )
|
, loaded : List ( Float, Float )
|
||||||
, volume : Float
|
, volume : Float
|
||||||
, muted : Bool
|
, muted : Bool
|
||||||
|
, isFullscreen : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,17 +42,30 @@ type Msg
|
||||||
= Noop
|
= Noop
|
||||||
| PlayPause
|
| PlayPause
|
||||||
| Seek Float
|
| Seek Float
|
||||||
|
| RequestFullscreen
|
||||||
|
| ExitFullscreen
|
||||||
| NowPlaying
|
| NowPlaying
|
||||||
| NowPaused
|
| NowPaused
|
||||||
| NowHasDuration Float
|
| NowHasDuration Float
|
||||||
| NowAtPosition Float
|
| NowAtPosition Float
|
||||||
| NowAtVolume Float Bool
|
| NowAtVolume Float Bool
|
||||||
| NowLoaded (List ( Float, Float ))
|
| NowLoaded (List ( Float, Float ))
|
||||||
|
| NowIsFullscreen Bool
|
||||||
|
|
||||||
|
|
||||||
init : ( Model, Cmd Msg )
|
init : ( Model, Cmd Msg )
|
||||||
init =
|
init =
|
||||||
( Model "video/manifest.m3u8" False 0.0 1.0 [] 1.0 False, initVideo () )
|
( Model
|
||||||
|
"video/manifest.m3u8"
|
||||||
|
False
|
||||||
|
0.0
|
||||||
|
1.0
|
||||||
|
[]
|
||||||
|
1.0
|
||||||
|
False
|
||||||
|
False
|
||||||
|
, initVideo ()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
|
@ -66,6 +80,12 @@ update msg model =
|
||||||
Seek ratio ->
|
Seek ratio ->
|
||||||
( model, seek (ratio * model.duration) )
|
( model, seek (ratio * model.duration) )
|
||||||
|
|
||||||
|
RequestFullscreen ->
|
||||||
|
( model, requestFullscreen () )
|
||||||
|
|
||||||
|
ExitFullscreen ->
|
||||||
|
( model, exitFullscreen () )
|
||||||
|
|
||||||
NowPlaying ->
|
NowPlaying ->
|
||||||
( { model | playing = True }, Cmd.none )
|
( { model | playing = True }, Cmd.none )
|
||||||
|
|
||||||
|
@ -84,6 +104,9 @@ update msg model =
|
||||||
NowLoaded loaded ->
|
NowLoaded loaded ->
|
||||||
( { model | loaded = loaded }, Cmd.none )
|
( { model | loaded = loaded }, Cmd.none )
|
||||||
|
|
||||||
|
NowIsFullscreen fullscreen ->
|
||||||
|
( { model | isFullscreen = fullscreen }, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Browser.Document Msg
|
view : Model -> Browser.Document Msg
|
||||||
view model =
|
view model =
|
||||||
|
@ -178,13 +201,15 @@ video model =
|
||||||
, Element.el [ Element.width (Element.fillPortion remaining) ] Element.none
|
, Element.el [ Element.width (Element.fillPortion remaining) ] Element.none
|
||||||
]
|
]
|
||||||
, Element.row
|
, Element.row
|
||||||
[ Element.spacing 10 ]
|
[ Element.spacing 10, Element.width Element.fill ]
|
||||||
[ playPauseButton model.playing
|
[ playPauseButton model.playing
|
||||||
, Element.el [ Element.moveDown 2.5 ] (Element.text (formatTime model.position ++ " / " ++ formatTime model.duration))
|
, Element.el [ Element.moveDown 2.5 ] (Element.text (formatTime model.position ++ " / " ++ formatTime model.duration))
|
||||||
|
, Element.row [ Element.spacing 10, Element.alignRight ]
|
||||||
|
[ fullscreenButton model.isFullscreen ]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
Element.el [ Element.inFront bar, Element.width (Element.px 1000) ]
|
Element.el (Element.inFront bar :: Element.width (Element.px 1000) :: Element.htmlAttribute (Html.Attributes.id "full") :: playerEvents)
|
||||||
(Element.html (Html.video videoEvents []))
|
(Element.html (Html.video videoEvents []))
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,6 +229,28 @@ playPauseButton playing =
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fullscreenButton : Bool -> Element Msg
|
||||||
|
fullscreenButton isFullscreen =
|
||||||
|
Input.button []
|
||||||
|
(if isFullscreen then
|
||||||
|
{ label = Icons.minimize False
|
||||||
|
, onPress = Just ExitFullscreen
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{ label = Icons.maximize False
|
||||||
|
, onPress = Just RequestFullscreen
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
playerEvents : List (Element.Attribute Msg)
|
||||||
|
playerEvents =
|
||||||
|
List.map Element.htmlAttribute
|
||||||
|
[ Html.Events.on "fullscreenchange" decodeFullscreenChange
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
videoEvents : List (Html.Attribute Msg)
|
videoEvents : List (Html.Attribute Msg)
|
||||||
videoEvents =
|
videoEvents =
|
||||||
[ Html.Attributes.id "video"
|
[ Html.Attributes.id "video"
|
||||||
|
@ -254,12 +301,11 @@ decodeSeek =
|
||||||
|
|
||||||
decodeProgress : Decode.Decoder Msg
|
decodeProgress : Decode.Decoder Msg
|
||||||
decodeProgress =
|
decodeProgress =
|
||||||
Decode.map NowLoaded
|
|
||||||
(Dom.target <|
|
|
||||||
Decode.field "buffered" <|
|
|
||||||
Decode.field "asArray" <|
|
|
||||||
decodeTimeRanges
|
decodeTimeRanges
|
||||||
)
|
|> Decode.field "asArray"
|
||||||
|
|> Decode.field "buffered"
|
||||||
|
|> Dom.target
|
||||||
|
|> Decode.map NowLoaded
|
||||||
|
|
||||||
|
|
||||||
decodeTimeRanges : Decode.Decoder (List ( Float, Float ))
|
decodeTimeRanges : Decode.Decoder (List ( Float, Float ))
|
||||||
|
@ -274,6 +320,16 @@ decodeTimeRange =
|
||||||
(Decode.field "end" Decode.float)
|
(Decode.field "end" Decode.float)
|
||||||
|
|
||||||
|
|
||||||
|
decodeFullscreenChange : Decode.Decoder Msg
|
||||||
|
decodeFullscreenChange =
|
||||||
|
Decode.value
|
||||||
|
|> Decode.nullable
|
||||||
|
|> Decode.field "fullscreenElement"
|
||||||
|
|> Decode.field "document"
|
||||||
|
|> Dom.target
|
||||||
|
|> Decode.map (\x -> NowIsFullscreen (x /= Nothing))
|
||||||
|
|
||||||
|
|
||||||
every : Float -> List ( Float, Float ) -> List ( Float, Float, Bool )
|
every : Float -> List ( Float, Float ) -> List ( Float, Float, Bool )
|
||||||
every duration input =
|
every duration input =
|
||||||
everyAux duration 0.0 [] input |> List.reverse |> List.filter (\( x, y, _ ) -> x /= y)
|
everyAux duration 0.0 [] input |> List.reverse |> List.filter (\( x, y, _ ) -> x /= y)
|
||||||
|
@ -338,3 +394,9 @@ port playPause : () -> Cmd msg
|
||||||
|
|
||||||
|
|
||||||
port seek : Float -> Cmd msg
|
port seek : Float -> Cmd msg
|
||||||
|
|
||||||
|
|
||||||
|
port requestFullscreen : () -> Cmd msg
|
||||||
|
|
||||||
|
|
||||||
|
port exitFullscreen : () -> Cmd msg
|
||||||
|
|
Loading…
Reference in New Issue