I'm using Xampp
server to access my video file and then play it on my website. I'm using a XMLHttpRequest
to obtain the video file and then put it as the source of the video player. But I'm getting an error. I have tried to solve the problem by inserting Header set Access-Control-Allow-Origin "*"
but I'm still not able to fix the problem. I have given my codes and the error below. Please Help Me.
Also I do not want any suggestion on alternative method of showing the video. I wish to use the XMLHttpRequest
.
My sample code:
<html>
<head>
<meta charset="utf-8"/>
<title></title>
</head>
<body>
<video video-player width="640" height="360" controls></video>
<script>
var video_player = document.querySelectorAll('[video-player]')[0];
// I ORIGINALLY USE MY http://localhost:8080/.... FOR THE 'var url' BUT FOR STACKOVERFLOW I'M USING THE LINK BELOW AS AN EXAMPLE
var url = "http://dash.akamaized.net/akamai/bbb/bbb_1280x720_60fps_6000k.mp4";
request_xhr (url, function (buffer)
{
video_player.src = buffer;
});
function request_xhr (url, cb)
{
var xhr = new XMLHttpRequest;
xhr.withCredentials = true;
xhr.open('get', url, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function ()
{
cb(xhr.response);
};
xhr.send();
}
</script>
</body>
</html>
My .htaccess
in the directory C:\xampp\htdocs\
:
Header set Access-Control-Allow-Origin "*"