A minimal web player written in Elm, just for fun. The goals was a minimal web-app that can be hosted on my Minio (s3) next to the video content.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.0 KiB

8 months ago
module Video exposing (..)
import Html
import Html.Attributes
8 months ago
import Json.Decode
8 months ago
type alias Video =
{ title : String
, path : String
}
8 months ago
type alias FileFormat =
{ extention : String
, mime : String
}
8 months ago
videoListDecoder : Json.Decode.Decoder (List Video)
videoListDecoder =
Json.Decode.list videoDecoder
8 months ago
videoDecoder : Json.Decode.Decoder Video
videoDecoder =
Json.Decode.map2 Video
(Json.Decode.field "Title" Json.Decode.string)
(Json.Decode.field "Path" Json.Decode.string)
htmlSourceElem : String -> FileFormat -> Html.Html msg
htmlSourceElem path format =
Html.source
[ Html.Attributes.src (path ++ "." ++ format.extention)
, Html.Attributes.type_ format.mime
]
[]
downloadLink : String -> FileFormat -> Html.Html msg
downloadLink path format =
Html.a
[ Html.Attributes.href (path ++ "." ++ format.extention)
, Html.Attributes.download <| filename path format
]
[ Html.text <| filename path format ]
filename : String -> FileFormat -> String
filename path format =
(Maybe.withDefault "unknown" <| List.head <| List.take 1 <| List.reverse <| String.split "/" path) ++ "." ++ format.extention
type alias ListConfig msg =
{ selected : Maybe String
, extensions : List FileFormat
, attrs : List (Html.Attribute msg)
}
downloadList : ListConfig msg -> Html.Html msg
downloadList config =
case config.selected of
Nothing ->
Html.div [] []
Just path ->
Html.div config.attrs <|
List.map (\e -> downloadLink path e) config.extensions
type alias PlayerConfig msg =
{ path : Maybe String
, extensions : List FileFormat
, attrs : List (Html.Attribute msg)
}
makePlayer : PlayerConfig msg -> Html.Html msg
makePlayer config =
case config.path of
Nothing ->
Html.div [] []
Just path ->
Html.video config.attrs (List.map (htmlSourceElem path) config.extensions)