Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Make Download Button Actually Download File


Hi,

I added a download button but what I was expecting it to do was actually download the file playing to the user's device. Instead, it just refreshes the player to the source file (I guess that's how to word it?). This seems like an obvious feature, so I'm baffled as to why it seems so convoluted to make it function.

The player in question is located here directly under "Current Sermon"
http://www.livinghopesda.com/

My code:
<script src="//content.jwplatform.com/players/l9aqB9m4-7l7ZMsAW.js"></script>
<script>jwplayer("botr_l9aqB9m4_7l7ZMsAW_div").addButton(
"http://static.wixstatic.com/media/97b69b_319acd6172574c9e9c536748185f1253.png/v1/fill/w_40,h_40,al_c/97b69b_319acd6172574c9e9c536748185f1253.png","Download",
function() {
//Link to the actual file below:
window.location.href = 'http://content.jwplatform.com/videos/l9aqB9m4-EnqDUKfa.m4a';
},"download");
</script>

Thanks!




<script>
jwplayer("botr_l9aqB9m4_7l7ZMsAW_div").addButton(
//This portion is what designates the graphic used for the button
"http://static.wixstatic.com/media/97b69b_bad03957881648f79c17f33ef58c5ffa.png/v1/fill/w_40,h_40,al_c/97b69b_bad03957881648f79c17f33ef58c5ffa.png",
//This portion determines the text that appears as a tooltip
"Download",
//This portion designates the functionality of the button itself
function() {
//With the below code, we're grabbing the file that's currently playing
window.location.href = 'http://www.stephaniequinn.com/Music/Allegro%20from%20Duet%20in%20C%20Major.mp3'; //This si the file I'd like the person to download
},
//And finally, here we set the unique ID of the button itself.
"download"
);
</script>

4 Community Answers

Alex

JW Player Support Agent  
0 rated :

Hi, there.

If the browser natively supports playback of the media file you are trying to link to, then the browser will just load the file instead of downloading it for the user. This is functionality built in to the browsers themselves. Users can change their specific browser settings to not “open” the files, which is essentially what is happening, but there is no workaround to force this behavior on users. I have seen some customers put a notice near the player to advise the viewer to right-click on the player when that file loads and choose “Save Video As…”.

Please let me know if you need any more help or have any other questions.

Thank you!

aaronbjohnsen

User  
0 rated :

Thanks for the response Alex.

One question then, the example on https://support.jwplayer.com/customer/portal/articles/1436999-example-adding-a-download-button
has the video open in the browser when clicking on the download button.

Our code is virtually the same, et clicking the download button only refreshes the player, so when I right-click it only allows me to save it as a webpage, whereas in the example you can download it as an mp4. How can I achieve that?

Alex

JW Player Support Agent  
0 rated :

Hi, Aaron.

Since you are using an embed that you generated via your Account Dashboard, it essentially creates an iFrame on your page and puts the player in there. So, when you click on the link, just the page within the iFrame changes. For security reason, there is unfortunately no way to change that behavior via JavaScript.

Honestly, in your use case, what I would suggest would be to have a link underneath the player that says something like Download Current Sermon (right-click and choose ‘Save As…’. It would look something like this: http://qa.jwplayer.com/~abussey/demos/feb2016/72499-download.html

Please let me know if you need any more help or have any other questions.

Thank you!

James Herrieven

User  
0 rated :

@aaronbjohnsen

Check out this example I've put together for you which *should* download the file rather than open it in the browser window:

http://dev.powered-by-haiku.co.uk/debug/livinghopesda/

Change the "downloadLink" file to target a different file for download.

James Herrieven
===================================================
Powered by Haiku
http://powered-by-haiku.co.uk/
---------------------------------------------------
Tatami for Online Video
http://dev.powered-by-haiku.co.uk/solutions/tatami/
---------------------------------------------------
skype: JamesHerrieven
email: james[at]haiku[dot]co[dot]uk
===================================================

This question has received the maximum number of answers.