0

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

AJAX cross domain call

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?

Brian
  • 63
  • 1
  • 5
  • Why are you involving Ajax at all? – Quentin Feb 11 '22 at 12:23
  • How do I overcome CORS otherwise? I've no access to the remote server, so I suppose the only option is to create a proxy on my server which in turn will send back data to the browser - without breaking CORS rule. – Brian Feb 11 '22 at 12:45
  • "so I suppose the only option is to create a proxy on my server which in turn will send back data to the browser" — which you've done. Now make it use GET and put the URL in the `src` attribute. – Quentin Feb 11 '22 at 14:31
  • I was trying to gain some bandwidth, but I found that most cloud storage providers don't allow their clients to edit HTTP headers (except AWS). – Brian Feb 15 '22 at 10:50

1 Answers1

-2

We can use AJAX to make a request to our local server, and then use a proxy such as Express JS (Node JS) which is able to route the request to the local video we want to stream. But streaming a video from a remote server (eg. mediafire.com) requires full access to the HTTP Headers, which they're usually not willing to provide.

Brian
  • 63
  • 1
  • 5
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/31053493) – Littm Feb 13 '22 at 08:32
  • OK, got it thanks. Probably a better answer is: we can use AJAX to make a request to our local server, and then use a proxy such as Express JS (Node JS) which is able to route the request to the local video we want to stream. But streaming a video from a remote server (eg. mediafire.com) requires full access to the HTTP Headers, which they're usually not willing to provide. – Brian Feb 13 '22 at 13:03