Clean
This commit is contained in:
parent
d1bd418e89
commit
b41c62e938
|
@ -11,7 +11,7 @@
|
||||||
<script src="js/main.js"></script>
|
<script src="js/main.js"></script>
|
||||||
<script src="js/ports.js"></script>
|
<script src="js/ports.js"></script>
|
||||||
<script>
|
<script>
|
||||||
embed({
|
PolymnyVideo.embed({
|
||||||
node: document.getElementById("container"),
|
node: document.getElementById("container"),
|
||||||
url: "video/manifest.m3u8",
|
url: "video/manifest.m3u8",
|
||||||
});
|
});
|
||||||
|
|
21
js/ports.js
21
js/ports.js
|
@ -14,7 +14,11 @@ Object.defineProperty(HTMLElement.prototype, "polymnyVideoDocument", {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function embed(options) {
|
const PolymnyVideo = (function() {
|
||||||
|
|
||||||
|
const PolymnyVideo = {};
|
||||||
|
|
||||||
|
PolymnyVideo.embed = function(options) {
|
||||||
if (!(options.node instanceof HTMLElement)) {
|
if (!(options.node instanceof HTMLElement)) {
|
||||||
throw new Error("options.node must be an HTMLElement");
|
throw new Error("options.node must be an HTMLElement");
|
||||||
}
|
}
|
||||||
|
@ -28,11 +32,11 @@ function embed(options) {
|
||||||
options.height = window.innerHeight;
|
options.height = window.innerHeight;
|
||||||
|
|
||||||
const app = Elm.Examples.Embed.init(options);
|
const app = Elm.Examples.Embed.init(options);
|
||||||
setupApp(app);
|
PolymnyVideo.setup(app);
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
function setupApp(app) {
|
PolymnyVideo.setup = function(app) {
|
||||||
let hls;
|
let hls;
|
||||||
|
|
||||||
app.ports.polymnyVideoInit.subscribe(function(arg) {
|
app.ports.polymnyVideoInit.subscribe(function(arg) {
|
||||||
|
@ -68,6 +72,10 @@ function setupApp(app) {
|
||||||
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
||||||
video.src = arg[1];
|
video.src = arg[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arg[2]) {
|
||||||
|
video.play();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -128,4 +136,7 @@ function setupApp(app) {
|
||||||
hls.subtitleTrack = arg[1];
|
hls.subtitleTrack = arg[1];
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
|
return PolymnyVideo;
|
||||||
|
})();
|
||||||
|
|
|
@ -64,7 +64,7 @@ init flags =
|
||||||
|> Result.withDefault 0
|
|> Result.withDefault 0
|
||||||
|
|
||||||
( video, cmd ) =
|
( video, cmd ) =
|
||||||
Video.fromUrl url "video"
|
Video.fromConfig { url = url, id = "video", autoplay = True }
|
||||||
in
|
in
|
||||||
( { video = video, screenSize = ( width, height ) }
|
( { video = video, screenSize = ( width, height ) }
|
||||||
, Cmd.map VideoMsg cmd
|
, Cmd.map VideoMsg cmd
|
||||||
|
|
|
@ -3,7 +3,7 @@ port module Video exposing
|
||||||
, Settings(..)
|
, Settings(..)
|
||||||
, SubtitleTrack
|
, SubtitleTrack
|
||||||
, Video
|
, Video
|
||||||
, fromUrl
|
, fromConfig
|
||||||
, init
|
, init
|
||||||
, nowHasQualities
|
, nowHasQualities
|
||||||
, nowHasQuality
|
, nowHasQuality
|
||||||
|
@ -44,10 +44,17 @@ type alias Video =
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fromUrl : String -> String -> ( Video, Cmd Msg )
|
type alias Config =
|
||||||
fromUrl url id =
|
{ url : String
|
||||||
( { url = url
|
, id : String
|
||||||
, id = id
|
, autoplay : Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fromConfig : Config -> ( Video, Cmd Msg )
|
||||||
|
fromConfig config =
|
||||||
|
( { url = config.url
|
||||||
|
, id = config.id
|
||||||
, playing = False
|
, playing = False
|
||||||
, position = 0
|
, position = 0
|
||||||
, duration = 0
|
, duration = 0
|
||||||
|
@ -69,7 +76,7 @@ fromUrl url id =
|
||||||
, showIcon = Nothing
|
, showIcon = Nothing
|
||||||
, showIconRequested = Nothing
|
, showIconRequested = Nothing
|
||||||
}
|
}
|
||||||
, init id url
|
, init config.id config.url config.autoplay
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -265,12 +272,12 @@ update msg model =
|
||||||
( { model | showMiniature = miniature }, Cmd.none )
|
( { model | showMiniature = miniature }, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
port polymnyVideoInit : ( String, String ) -> Cmd msg
|
port polymnyVideoInit : ( String, String, Bool ) -> Cmd msg
|
||||||
|
|
||||||
|
|
||||||
init : String -> String -> Cmd msg
|
init : String -> String -> Bool -> Cmd msg
|
||||||
init id url =
|
init id url autoplay =
|
||||||
polymnyVideoInit ( id, url )
|
polymnyVideoInit ( id, url, autoplay )
|
||||||
|
|
||||||
|
|
||||||
port polymnyVideoPlayPause : String -> Cmd msg
|
port polymnyVideoPlayPause : String -> Cmd msg
|
||||||
|
|
|
@ -258,24 +258,10 @@ overlay model =
|
||||||
(Element.width Element.fill
|
(Element.width Element.fill
|
||||||
:: Element.height Element.fill
|
:: Element.height Element.fill
|
||||||
:: Font.color (Element.rgb 1 1 1)
|
:: Font.color (Element.rgb 1 1 1)
|
||||||
:: (if not model.playing then
|
|
||||||
Background.color (Element.rgba 0 0 0 0.5)
|
|
||||||
|
|
||||||
else
|
|
||||||
Background.color (Element.rgba 0 0 0 0)
|
|
||||||
)
|
|
||||||
:: Events.overlay
|
:: Events.overlay
|
||||||
)
|
)
|
||||||
(case ( model.playing, model.showIcon ) of
|
(case model.showIcon of
|
||||||
( False, _ ) ->
|
Just icon ->
|
||||||
Element.el
|
|
||||||
[ Element.centerX
|
|
||||||
, Element.centerY
|
|
||||||
, Element.scale 10
|
|
||||||
]
|
|
||||||
(Icons.play True)
|
|
||||||
|
|
||||||
( _, Just icon ) ->
|
|
||||||
animatedEl fadeOutZoom
|
animatedEl fadeOutZoom
|
||||||
[ Background.color (Element.rgb 0 0 0)
|
[ Background.color (Element.rgb 0 0 0)
|
||||||
, Border.rounded 100
|
, Border.rounded 100
|
||||||
|
|
Loading…
Reference in New Issue