Skip to content

Commit

Permalink
Remove console log
Browse files Browse the repository at this point in the history
  • Loading branch information
Eimi Okuno committed Apr 29, 2020
1 parent 79caffa commit a265570
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/PreviewCanvas/VideoContextPreview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const VideoContextPreview = (props) => {
const canvasRef = props.canvasRef;
const [ videoContext, setVideoContext ] = useState();
const [ duration, setDuration ] = useState(0);
const [ sourceNodes, setSourceNodes ] = useState([]);

useEffect(() => {
if (canvasRef && canvasRef.current) {
Expand All @@ -23,8 +22,8 @@ const VideoContextPreview = (props) => {

useEffect(() => {
const updateVideoContext = () => {
const vc = new VideoContext(canvasRef.current);
props.playlist.forEach((media) => {
videoContext.reset();
const connectVideoContext = (media) => {
const {
type,
sourceStart,
Expand All @@ -33,22 +32,22 @@ const VideoContextPreview = (props) => {
src,
} = media;
const end = start + mediaDuration;
const node = vc[type](src, sourceStart);
const node = videoContext[type](src, sourceStart);

node.startAt(start);
node.stopAt(end);
node.connect(vc.destination);
});
setVideoContext(vc);
setDuration(vc.duration);
setSourceNodes(vc._sourceNodes);
node.connect(videoContext.destination);
};
props.playlist.forEach((media) =>
connectVideoContext(media, videoContext)
);

setDuration(videoContext.duration);
};

// we will always add or remove, not edit in-place
if (sourceNodes.length !== props.playlist.length) {
if (videoContext) {
updateVideoContext();
}

}, [ props.playlist, videoContext ]);

const handleStop = () => {
Expand All @@ -60,6 +59,8 @@ const VideoContextPreview = (props) => {
});
};

const formattedDuration = secondsToHHMMSSFormat(duration);

return (
<>
<Row
Expand Down Expand Up @@ -91,7 +92,7 @@ const VideoContextPreview = (props) => {
</Row>

<Row className={ 'justify-content-center' }>
Total duration: {secondsToHHMMSSFormat(duration)}
Total duration: {formattedDuration}
</Row>
</>
);
Expand All @@ -100,7 +101,7 @@ const VideoContextPreview = (props) => {
VideoContextPreview.propTypes = {
canvasRef: PropTypes.any,
playlist: PropTypes.array,
width: PropTypes.number
width: PropTypes.number,
};

export default VideoContextPreview;

0 comments on commit a265570

Please sign in to comment.