2021-06-21 11:05:25 +02:00
|
|
|
module Examples.Embed exposing (..)
|
2021-06-09 11:00:36 +02:00
|
|
|
|
|
|
|
import Browser
|
2021-06-10 08:55:13 +02:00
|
|
|
import Browser.Events
|
2021-06-11 11:39:12 +02:00
|
|
|
import Element exposing (Element)
|
2021-06-09 11:00:36 +02:00
|
|
|
import Element.Background as Background
|
|
|
|
import Element.Border as Border
|
|
|
|
import Element.Font as Font
|
|
|
|
import Element.Input as Input
|
|
|
|
import Html
|
|
|
|
import Html.Attributes
|
|
|
|
import Html.Events
|
|
|
|
import Json.Decode as Decode
|
2021-06-10 08:55:13 +02:00
|
|
|
import Simple.Animation as Animation exposing (Animation)
|
|
|
|
import Simple.Animation.Animated as Animated
|
|
|
|
import Simple.Animation.Property as P
|
2021-06-14 12:02:55 +02:00
|
|
|
import Video exposing (Video)
|
2021-06-21 11:05:25 +02:00
|
|
|
import Video.Events as Events
|
|
|
|
import Video.Views as Views
|
2021-06-09 11:00:36 +02:00
|
|
|
|
|
|
|
|
2021-06-10 15:06:58 +02:00
|
|
|
main : Program Decode.Value Model Msg
|
2021-06-09 11:00:36 +02:00
|
|
|
main =
|
|
|
|
Browser.application
|
2021-06-09 18:59:20 +02:00
|
|
|
{ init = \url _ _ -> init url
|
2021-06-09 11:00:36 +02:00
|
|
|
, update = update
|
|
|
|
, view = view
|
2021-06-10 08:55:13 +02:00
|
|
|
, subscriptions =
|
2021-06-14 10:46:34 +02:00
|
|
|
\model ->
|
2021-06-10 08:55:13 +02:00
|
|
|
Sub.batch
|
2021-06-14 12:02:55 +02:00
|
|
|
[ Events.subs model.video |> Sub.map VideoMsg
|
|
|
|
, Browser.Events.onResize (\x y -> NowHasScreenSize ( x, y ))
|
2021-06-10 08:55:13 +02:00
|
|
|
]
|
2021-06-09 11:00:36 +02:00
|
|
|
, onUrlChange = \_ -> Noop
|
|
|
|
, onUrlRequest = \_ -> Noop
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type alias Model =
|
2021-06-14 12:02:55 +02:00
|
|
|
{ video : Video
|
2021-06-10 15:06:58 +02:00
|
|
|
, screenSize : ( Int, Int )
|
2021-06-09 11:00:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type Msg
|
|
|
|
= Noop
|
2021-06-14 12:02:55 +02:00
|
|
|
| VideoMsg Video.Msg
|
|
|
|
| NowHasScreenSize ( Int, Int )
|
2021-06-09 11:00:36 +02:00
|
|
|
|
|
|
|
|
2021-06-10 15:06:58 +02:00
|
|
|
init : Decode.Value -> ( Model, Cmd Msg )
|
|
|
|
init flags =
|
|
|
|
let
|
|
|
|
url =
|
|
|
|
Decode.decodeValue (Decode.field "url" Decode.string) flags
|
|
|
|
|> Result.withDefault "manifest.m3u8"
|
|
|
|
|
|
|
|
width =
|
|
|
|
Decode.decodeValue (Decode.field "width" Decode.int) flags
|
|
|
|
|> Result.withDefault 0
|
|
|
|
|
|
|
|
height =
|
|
|
|
Decode.decodeValue (Decode.field "height" Decode.int) flags
|
|
|
|
|> Result.withDefault 0
|
2021-06-21 11:05:25 +02:00
|
|
|
|
|
|
|
( video, cmd ) =
|
2021-06-21 14:34:27 +02:00
|
|
|
Video.fromConfig { url = url, id = "video", autoplay = True }
|
2021-06-10 15:06:58 +02:00
|
|
|
in
|
2021-06-21 11:05:25 +02:00
|
|
|
( { video = video, screenSize = ( width, height ) }
|
|
|
|
, Cmd.map VideoMsg cmd
|
2021-06-09 17:19:42 +02:00
|
|
|
)
|
2021-06-09 11:00:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
|
|
update msg model =
|
|
|
|
case msg of
|
|
|
|
Noop ->
|
|
|
|
( model, Cmd.none )
|
|
|
|
|
2021-06-14 12:02:55 +02:00
|
|
|
VideoMsg m ->
|
|
|
|
let
|
|
|
|
( video, cmd ) =
|
|
|
|
Video.update m model.video
|
|
|
|
in
|
|
|
|
( { model | video = video }, Cmd.map VideoMsg cmd )
|
2021-06-10 15:06:58 +02:00
|
|
|
|
2021-06-14 12:02:55 +02:00
|
|
|
NowHasScreenSize size ->
|
2021-06-10 15:06:58 +02:00
|
|
|
( { model | screenSize = size }, Cmd.none )
|
|
|
|
|
2021-06-09 11:00:36 +02:00
|
|
|
|
|
|
|
view : Model -> Browser.Document Msg
|
|
|
|
view model =
|
|
|
|
{ title = "Hello"
|
2021-06-14 12:02:55 +02:00
|
|
|
, body =
|
|
|
|
[ Element.layout [ Element.height Element.fill ]
|
|
|
|
(Element.map VideoMsg (Views.embed model.screenSize model.video))
|
2021-06-09 11:00:36 +02:00
|
|
|
]
|
2021-06-14 12:02:55 +02:00
|
|
|
}
|