Failed to load resource: the server responded with a status of 404 (Not Found)
Hello, I'm doing a video looping with auto-play. My video looping was working before and the videos were play. But after I put some adjustments on my page and my logic, it was broken and the videos were not play. I got the error Failed to load resource: the server responded with a status of 404 (Not Found)
js code
<script type="text/javascript">
var vidElement = document.getElementById('video');
var vidSources = [
@foreach($videos as $video)
"{{ $video->video_file }}",
@endforeach
];
var activeVideo = Math.floor((Math.random() * vidSources.length));
vidElement.src = vidSources[activeVideo];
vidElement.addEventListener('ended', function(e) {
// update the active video index
activeVideo = (++activeVideo) % vidSources.length;
if(activeVideo === vidSources.length){
activeVideo = 0;
}
// update the video source and play
vidElement.src = vidSources[activeVideo];
vidElement.play();
});
</script>
Yes I see it sir on the network tab. It said Failed to response data. And by the way, I see in the console tab that I use the blade syntax, in the console it provides the video files so I think it is not a problem if you use a blade syntax file on the script code
<script >
var vidElement = document.getElementById('video');
var videos = JSON.parse('@json($videos)');
var vidSources = [];
for (let i in videos) {
vidSources.push(videos[i].video_file)
}
var activeVideo = Math.floor((Math.random() * vidSources.length));
vidElement.src = vidSources[activeVideo];
vidElement.addEventListener('ended', function(e) {
// update the active video index
activeVideo = (++activeVideo) % vidSources.length;
if (activeVideo === vidSources.length) {
activeVideo = 0;
}
// update the video source and play
vidElement.src = vidSources[activeVideo];
vidElement.play();
});
</script>
@bosspogs How does the videos get into the database? It might be worth looking into saving the file in the correct place with the correct name, when you add them to the database :)