Support time
This commit is contained in:
parent
42de337746
commit
a1ccbbefa3
15
index.html
15
index.html
|
@ -17,9 +17,22 @@
|
||||||
flags: { width: window.innerWidth, height: window.innerHeight }
|
flags: { width: window.innerWidth, height: window.innerHeight }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var lastId, player;
|
||||||
|
|
||||||
app.ports.registerVideo.subscribe(function(args) {
|
app.ports.registerVideo.subscribe(function(args) {
|
||||||
|
var time = parseInt(args[2], 10) || undefined;
|
||||||
|
|
||||||
requestAnimationFrame(function() {
|
requestAnimationFrame(function() {
|
||||||
vd.setup(args[0], args[1] + "/manifest.mpd")
|
if (args[0] !== lastId) {
|
||||||
|
lastId = args[0];
|
||||||
|
|
||||||
|
player = vd.setup(args[0], {
|
||||||
|
v: args[1] + "/manifest.mpd",
|
||||||
|
t: parseInt(args[2], 10) || 0
|
||||||
|
});
|
||||||
|
} else if (time !== undefined ){
|
||||||
|
player.currentTime(time);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
45
src/Core.elm
45
src/Core.elm
|
@ -2,6 +2,7 @@ module Core exposing (FullModel(..), Model, Msg(..), Page(..), init, subscriptio
|
||||||
|
|
||||||
import Browser.Events as Events
|
import Browser.Events as Events
|
||||||
import Browser.Navigation as Nav
|
import Browser.Navigation as Nav
|
||||||
|
import Dict exposing (Dict)
|
||||||
import Element
|
import Element
|
||||||
import Ports
|
import Ports
|
||||||
import Task
|
import Task
|
||||||
|
@ -85,9 +86,32 @@ update msg model =
|
||||||
|
|
||||||
( UrlReceived url, Loaded m ) ->
|
( UrlReceived url, Loaded m ) ->
|
||||||
let
|
let
|
||||||
split =
|
splits =
|
||||||
String.split "/" (Maybe.withDefault "" url.fragment)
|
String.split "?" (Maybe.withDefault "" url.fragment)
|
||||||
|
|
||||||
|
( split, args ) =
|
||||||
|
case splits of
|
||||||
|
h1 :: h2 :: _ ->
|
||||||
|
( String.split "/" h1, parseQueryString h2 )
|
||||||
|
|
||||||
|
h1 :: _ ->
|
||||||
|
( String.split "/" h1, Dict.empty )
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
( [], Dict.empty )
|
||||||
|
|
||||||
|
time =
|
||||||
|
case Maybe.map String.toInt (Dict.get "t" args) of
|
||||||
|
Just (Just 0) ->
|
||||||
|
Nothing
|
||||||
|
|
||||||
|
Just (Just t) ->
|
||||||
|
Just t
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
Nothing
|
||||||
|
|
||||||
|
-- String.split "/" (Maybe.withDefault "" (List.head splits))
|
||||||
( playlistName, videoName ) =
|
( playlistName, videoName ) =
|
||||||
case split of
|
case split of
|
||||||
p :: v :: _ ->
|
p :: v :: _ ->
|
||||||
|
@ -114,7 +138,7 @@ update msg model =
|
||||||
case ( playlist, video ) of
|
case ( playlist, video ) of
|
||||||
( Just p, Just v ) ->
|
( Just p, Just v ) ->
|
||||||
( Video p v
|
( Video p v
|
||||||
, Ports.registerVideo ( Twitch.videoId v, v.url )
|
, Ports.registerVideo ( Twitch.videoId v, v.url, time )
|
||||||
)
|
)
|
||||||
|
|
||||||
( Just p, Nothing ) ->
|
( Just p, Nothing ) ->
|
||||||
|
@ -127,3 +151,18 @@ update msg model =
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
( model, Cmd.none )
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
|
splitter : String -> Maybe ( String, String )
|
||||||
|
splitter input =
|
||||||
|
case String.split "=" input of
|
||||||
|
h :: t ->
|
||||||
|
Just ( h, String.join "=" t )
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
Nothing
|
||||||
|
|
||||||
|
|
||||||
|
parseQueryString : String -> Dict String String
|
||||||
|
parseQueryString input =
|
||||||
|
Dict.fromList (List.filterMap splitter (String.split "&" input))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
port module Ports exposing (registerVideo)
|
port module Ports exposing (registerVideo)
|
||||||
|
|
||||||
|
|
||||||
port registerVideo : ( String, String ) -> Cmd msg
|
port registerVideo : ( String, String, Maybe Int ) -> Cmd msg
|
||||||
|
|
Loading…
Reference in New Issue