diff --git a/src/App.js b/src/App.js
index bc93506..81153f9 100644
--- a/src/App.js
+++ b/src/App.js
@@ -8,18 +8,9 @@ function App() {
{title ?
-
{title}
+
+
{title}
+
:
[untitled]
}
{media ?

: null}
diff --git a/src/features/video/VideoPlayer.js b/src/features/video/VideoPlayer.js
index 634c7d5..cd7326f 100644
--- a/src/features/video/VideoPlayer.js
+++ b/src/features/video/VideoPlayer.js
@@ -7,6 +7,7 @@ export default function VideoPlayer({data, src}) {
const [playing, setPlaying] = useState(false); // handles play/pause logic
const [audio, setAudio] = useState(null);
+ const [video, setVideo] = useState(null);
const crossPostSrc = src;
@@ -38,18 +39,34 @@ export default function VideoPlayer({data, src}) {
}
}
+ const checkForVideo = async(source) => {
+ try {
+ await fetch(source)
+ .then((response) => {
+ if (response.status > 400) {
+ setVideo(null);
+ } else {
+ setVideo(source);
+ }
+ });
+ } catch(e) {
+ console.log(e);
+ }
+ }
+
if (checking) {
checkForAudio();
+ checkForVideo(data.media.reddit_video.fallback_url);
checking = false;
}
return () => {
checking = false;
}
- }, [url, audio]);
+ }, [url, video, data, audio]);
useEffect(() => { // this section handles simultaneous playback of audio and video
- if (!audio) {
+ if (!audio || !video) {
return;
}
@@ -59,16 +76,18 @@ export default function VideoPlayer({data, src}) {
} else if (!playing) {
vid.current.pause();
}
- }, [playing, audio, aud, vid]);
+ }, [playing, video, audio, aud, vid]);
return (
+ <>
+ {!video ? null :
{
!audio ?
<>
-
+ }
+ >
);
}
\ No newline at end of file