I'm trying to create a simple www.myserver.com/proxy.php in order to stream www.mediafire/myvideo.mp4 back to the browser. I do this to avoid CORS error when calling the video directly from the browser. (mediafire server doesn't allows CORS)
In the post below I found the code, but:
How do I fetch the ajax response back to the element in VideoJS?
Many Thanks
The jQuery part:
$.ajax({
url: 'proxy.php',
type: 'POST',
success: function(response) {
// response now contains myfile.mp4
}
});
the PHP (proxy.php):
echo file_get_contents("www.mediafire.com/myvid.mp4");
And a simple VideoJS script:
<video
id="fplayer"
class="video-js vjs-default-skin vjs-16-9"
controls
preload="none"
data-setup='{"fluid": false}'>
<source src="??" type="application/x-mpegURL">
// it was: <source src="www.mediafire.com/myvid.mp4">
</video>
The link below suggest to build the HTML videoJS element once I get the ajax response. But the datatype is JSON, whereas I'm fetching a binary MP4 or a m3u8 video and I'm not sure if putting the response in the Source element will work. In addition VideoJS may not initialize using this solution because the Video element doesn't exist when page load is ready.
Load video source into videojs or mediaelementjs dynamically from ajax?