Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nos Hs2023
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Språksamlingane
stadnamn
Nos Hs2023
Commits
6cd5c4b3
Commit
6cd5c4b3
authored
3 years ago
by
esikkala
Browse files
Options
Downloads
Patches
Plain Diff
Add video player component
parent
439607bd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/client/actions/index.js
+5
-0
5 additions, 0 deletions
src/client/actions/index.js
src/client/components/main_layout/Player.js
+100
-0
100 additions, 0 deletions
src/client/components/main_layout/Player.js
with
105 additions
and
0 deletions
src/client/actions/index.js
+
5
−
0
View file @
6cd5c4b3
...
@@ -48,6 +48,7 @@ export const LOAD_LOCALES = 'LOAD_LOCALES'
...
@@ -48,6 +48,7 @@ export const LOAD_LOCALES = 'LOAD_LOCALES'
export
const
LOAD_LOCALES_FAILED
=
'
LOAD_LOCALES_FAILED
'
export
const
LOAD_LOCALES_FAILED
=
'
LOAD_LOCALES_FAILED
'
export
const
UPDATE_LOCALE
=
'
UPDATE_LOCALE
'
export
const
UPDATE_LOCALE
=
'
UPDATE_LOCALE
'
export
const
ANIMATE_MAP
=
'
ANIMATE_MAP
'
export
const
ANIMATE_MAP
=
'
ANIMATE_MAP
'
export
const
UPDATE_VIDEO_PLAYER_TIME
=
'
UPDATE_VIDEO_PLAYER_TIME
'
export
const
CLIENT_FS_UPDATE_QUERY
=
'
CLIENT_FS_UPDATE_QUERY
'
export
const
CLIENT_FS_UPDATE_QUERY
=
'
CLIENT_FS_UPDATE_QUERY
'
export
const
CLIENT_FS_TOGGLE_DATASET
=
'
CLIENT_FS_TOGGLE_DATASET
'
export
const
CLIENT_FS_TOGGLE_DATASET
=
'
CLIENT_FS_TOGGLE_DATASET
'
export
const
CLIENT_FS_FETCH_RESULTS
=
'
CLIENT_FS_FETCH_RESULTS
'
export
const
CLIENT_FS_FETCH_RESULTS
=
'
CLIENT_FS_FETCH_RESULTS
'
...
@@ -323,6 +324,10 @@ export const animateMap = value => ({
...
@@ -323,6 +324,10 @@ export const animateMap = value => ({
type
:
ANIMATE_MAP
,
type
:
ANIMATE_MAP
,
value
value
})
})
export
const
updateVideoPlayerTime
=
value
=>
({
type
:
UPDATE_VIDEO_PLAYER_TIME
,
value
})
export
const
updateMapBounds
=
({
resultClass
,
bounds
})
=>
({
export
const
updateMapBounds
=
({
resultClass
,
bounds
})
=>
({
type
:
UPDATE_MAP_BOUNDS
,
type
:
UPDATE_MAP_BOUNDS
,
resultClass
,
resultClass
,
...
...
This diff is collapsed.
Click to expand it.
src/client/components/main_layout/Player.js
0 → 100644
+
100
−
0
View file @
6cd5c4b3
import
React
from
'
react
'
import
{
withStyles
}
from
'
@material-ui/core/styles
'
const
styles
=
theme
=>
({
// https://www.w3schools.com/howto/howto_css_responsive_iframes.asp
container
:
{
position
:
'
relative
'
,
overflow
:
'
hidden
'
,
width
:
'
100%
'
,
paddingTop
:
'
56.25%
'
/* 16:9 Aspect Ratio (divide 9 by 16 = 0.5625) */
},
responsiveIframe
:
{
position
:
'
absolute
'
,
top
:
0
,
left
:
0
,
bottom
:
0
,
right
:
0
,
width
:
'
100%
'
,
height
:
'
100%
'
}
})
class
Player
extends
React
.
Component
{
componentDidMount
=
()
=>
{
// On mount, check to see if the API script is already loaded
if
(
!
window
.
YT
)
{
// If not, load the script asynchronously
const
tag
=
document
.
createElement
(
'
script
'
)
tag
.
src
=
'
https://www.youtube.com/iframe_api
'
// onYouTubeIframeAPIReady will load the video after the script is loaded
window
.
onYouTubeIframeAPIReady
=
this
.
loadVideo
const
firstScriptTag
=
document
.
getElementsByTagName
(
'
script
'
)[
0
]
firstScriptTag
.
parentNode
.
insertBefore
(
tag
,
firstScriptTag
)
}
else
{
// If script is already there, load the video directly
this
.
loadVideo
()
}
}
componentDidUpdate
=
prevProps
=>
{
if
(
this
.
props
.
routeProps
.
location
.
hash
!==
prevProps
.
routeProps
.
location
.
hash
)
{
this
.
seekToBasedOnHash
()
}
}
componentWillUnmount
()
{
if
(
this
.
videoTimer
)
{
clearInterval
(
this
.
videoTimer
)
}
}
seekToBasedOnHash
=
()
=>
{
const
seconds
=
this
.
props
.
routeProps
.
location
.
hash
.
substring
(
1
)
// https://developers.google.com/youtube/iframe_api_reference#seekTo
this
.
player
.
seekTo
(
seconds
)
}
loadVideo
=
()
=>
{
const
{
youTubeID
}
=
this
.
props
.
data
// the Player object is created uniquely based on the id in props
this
.
player
=
new
window
.
YT
.
Player
(
`youtube-player-
${
youTubeID
}
`
,
{
videoId
:
youTubeID
,
playerVars
:
{
// https://developers.google.com/youtube/player_parameters#Parameters
start
:
1
// the parameter value is a positive integer
},
events
:
{
onReady
:
this
.
onPlayerReady
,
onStateChange
:
this
.
onPlayerStateChange
}
})
}
onPlayerReady
=
event
=>
{
if
(
this
.
props
.
routeProps
.
location
.
hash
===
''
)
{
this
.
props
.
updateVideoPlayerTime
(
parseInt
(
this
.
player
.
getCurrentTime
()))
}
else
{
this
.
seekToBasedOnHash
()
}
this
.
videoTimer
=
setInterval
(()
=>
{
if
(
this
.
player
.
getPlayerState
()
===
1
||
this
.
player
.
getPlayerState
()
===
2
)
{
this
.
props
.
updateVideoPlayerTime
(
parseInt
(
this
.
player
.
getCurrentTime
()))
}
},
1000
)
}
onPlayerStateChange
=
event
=>
{
this
.
props
.
updateVideoPlayerTime
(
parseInt
(
this
.
player
.
getCurrentTime
()))
}
render
()
{
const
{
classes
}
=
this
.
props
return
(
<
div
className
=
{
classes
.
container
}
>
<
div
id
=
{
`youtube-player-
${
this
.
props
.
data
.
youTubeID
}
`
}
className
=
{
classes
.
responsiveIframe
}
/
>
<
/div
>
)
}
}
export
default
withStyles
(
styles
)(
Player
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment