-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
284 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { ipfsPathToURL } from "../../helpers/ipfs"; | ||
|
||
import { useEffect, useRef, useState } from "react"; | ||
|
||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faPlayCircle } from "@fortawesome/free-regular-svg-icons"; | ||
|
||
function Player(props) { | ||
const [isPreview, setPreview] = useState(true); | ||
|
||
const videoPreviewRef = useRef(); | ||
const videoRef = useRef(); | ||
|
||
const image = ipfsPathToURL(props.image); | ||
const animation = ipfsPathToURL(props.animation_url); | ||
|
||
const play = () => { | ||
if (animation) { | ||
console.log( | ||
"videoPreviewRef.current.currentTime", | ||
videoPreviewRef.current?.currentTime | ||
); | ||
setPreview(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (!isPreview) { | ||
console.log( | ||
"videoRef.current.currentTime", | ||
videoRef.current?.currentTime | ||
); | ||
|
||
videoRef.current.play(); | ||
} | ||
}, [isPreview]); | ||
|
||
return ( | ||
<div> | ||
{isPreview && ( | ||
<div> | ||
<video | ||
key={"image_" + image} | ||
ref={videoPreviewRef} | ||
autoPlay | ||
muted | ||
loop | ||
poster={image} | ||
className={props.className} | ||
> | ||
<source src={image} /> | ||
</video> | ||
{animation && ( | ||
<div className="play-button" onClick={play}> | ||
<FontAwesomeIcon icon={faPlayCircle} /> | ||
</div> | ||
)} | ||
</div> | ||
)} | ||
|
||
{!isPreview && ( | ||
<video | ||
key={"animation_" + animation} | ||
ref={videoRef} | ||
controls | ||
loop | ||
className={props.className} | ||
> | ||
<source src={animation} /> | ||
</video> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default Player; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export const getVideoPoster = (source) => { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
const video = document.createElement("video"); | ||
|
||
video.onloadedmetadata = () => { | ||
video.currentTime = 0; | ||
}; | ||
|
||
video.onseeked = () => { | ||
const canvas = document.createElement("canvas"); | ||
canvas.height = video.videoHeight; | ||
canvas.width = video.videoWidth; | ||
const context = canvas.getContext("2d"); | ||
context.drawImage(video, 0, 0, canvas.width, canvas.height); | ||
const img = new Image(); | ||
img.src = canvas.toBlob((blob) => { | ||
const file = new File([blob], "poster.png"); | ||
resolve(file); | ||
}, "image/png"); | ||
}; | ||
|
||
video.src = source; | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
0986434
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: