简体   繁体   中英

MP4 videos started playing instead of downloading in HTML5 web app

I have a HTML5 web application in which there is a form through which user submit the video and format they want to download. On form submission, the response return the requested video format URL and the download starts automatically.

Returned Video URL are not pointing to the resource directly. Instead it has redirection to the resource.

This is working fine for FLV files but not for MP4 files.

For FLV file download starts without any problem. But in case of MP4 files, a player is launching to play it.

This behavior is same for without redirected resource URL.

Below code is auto-generating for MP4 video on receiving response:

<video autoplay="" controls="" style="position:absolute; top:0; left:0; width:100%; height:100%"></video>

Please provide any solution to stop loading of the player and initiate the download in case of MP4 videos. I don't control the resource server.

AD7six is quit right but I would also change the content type:

   Content-Type: application/octet-stream

If you use both it'll work across browsers... The disposition header also allows you to specify a name for the to be downloaded file in case you want to change that or if you download through a PHP file

From this article :

<?php
$file = "filename.ext";

// Quick check to verify that the file exists
if( !file_exists($file) ) die("File not found");

// Force the download
header("Content-Disposition: attachment; filename="" . basename($file) . """);
header("Content-Length: " . filesize($file));
header("Content-Type: application/octet-stream;");
readfile($file);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM