Html5 audio element multiple source download preference












1















If I have an html5 audio element with multiple sources, is there a way I can specify which source should be used when the user wants to download the file vs playing it in the browser (or achieve a similar effect with javascript)? For example, if I have two files, test_file.opus and test_file.mp3, can I signal the browser to play the opus file when the user clicks play, but then to download the mp3 file when they right click and select "save audio as". Typically opus audio files can be smaller, but they can't be played very easily unless the user knows what they're doing.



        <audio controls preload="metadata">
<source src="test_file.opus" type="audio/ogg; codecs=opus">
<source src="test_file.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>


Quick Note: I realize I could provide a download link in an <a> tag next to the html5 audio element. I was just curious if there was a way to signal the browser which one should be downloaded vs played in the browser or if there was a way to achieve a similar effect using javascript.










share|improve this question

























  • I'm guessing the browser will allow you to download whatever is playing. Wouldn't that be preferable? The browser will have already cached the audio file, so downloading what's cached and playing seems beneficial.

    – Brad
    Nov 28 '18 at 3:23











  • @Brad I get what you're saying, but the main issue is that if the browser is playing the .opus audio file, then right clicking and selecting "save audio as" will download the .opus file. From my experience, not many people would know how to deal with .opus audio files.

    – origamifreak2
    Nov 28 '18 at 13:00


















1















If I have an html5 audio element with multiple sources, is there a way I can specify which source should be used when the user wants to download the file vs playing it in the browser (or achieve a similar effect with javascript)? For example, if I have two files, test_file.opus and test_file.mp3, can I signal the browser to play the opus file when the user clicks play, but then to download the mp3 file when they right click and select "save audio as". Typically opus audio files can be smaller, but they can't be played very easily unless the user knows what they're doing.



        <audio controls preload="metadata">
<source src="test_file.opus" type="audio/ogg; codecs=opus">
<source src="test_file.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>


Quick Note: I realize I could provide a download link in an <a> tag next to the html5 audio element. I was just curious if there was a way to signal the browser which one should be downloaded vs played in the browser or if there was a way to achieve a similar effect using javascript.










share|improve this question

























  • I'm guessing the browser will allow you to download whatever is playing. Wouldn't that be preferable? The browser will have already cached the audio file, so downloading what's cached and playing seems beneficial.

    – Brad
    Nov 28 '18 at 3:23











  • @Brad I get what you're saying, but the main issue is that if the browser is playing the .opus audio file, then right clicking and selecting "save audio as" will download the .opus file. From my experience, not many people would know how to deal with .opus audio files.

    – origamifreak2
    Nov 28 '18 at 13:00
















1












1








1








If I have an html5 audio element with multiple sources, is there a way I can specify which source should be used when the user wants to download the file vs playing it in the browser (or achieve a similar effect with javascript)? For example, if I have two files, test_file.opus and test_file.mp3, can I signal the browser to play the opus file when the user clicks play, but then to download the mp3 file when they right click and select "save audio as". Typically opus audio files can be smaller, but they can't be played very easily unless the user knows what they're doing.



        <audio controls preload="metadata">
<source src="test_file.opus" type="audio/ogg; codecs=opus">
<source src="test_file.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>


Quick Note: I realize I could provide a download link in an <a> tag next to the html5 audio element. I was just curious if there was a way to signal the browser which one should be downloaded vs played in the browser or if there was a way to achieve a similar effect using javascript.










share|improve this question
















If I have an html5 audio element with multiple sources, is there a way I can specify which source should be used when the user wants to download the file vs playing it in the browser (or achieve a similar effect with javascript)? For example, if I have two files, test_file.opus and test_file.mp3, can I signal the browser to play the opus file when the user clicks play, but then to download the mp3 file when they right click and select "save audio as". Typically opus audio files can be smaller, but they can't be played very easily unless the user knows what they're doing.



        <audio controls preload="metadata">
<source src="test_file.opus" type="audio/ogg; codecs=opus">
<source src="test_file.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>


Quick Note: I realize I could provide a download link in an <a> tag next to the html5 audio element. I was just curious if there was a way to signal the browser which one should be downloaded vs played in the browser or if there was a way to achieve a similar effect using javascript.







html5 audio download mp3 opus






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 2:52







origamifreak2

















asked Nov 21 '18 at 18:53









origamifreak2origamifreak2

386




386













  • I'm guessing the browser will allow you to download whatever is playing. Wouldn't that be preferable? The browser will have already cached the audio file, so downloading what's cached and playing seems beneficial.

    – Brad
    Nov 28 '18 at 3:23











  • @Brad I get what you're saying, but the main issue is that if the browser is playing the .opus audio file, then right clicking and selecting "save audio as" will download the .opus file. From my experience, not many people would know how to deal with .opus audio files.

    – origamifreak2
    Nov 28 '18 at 13:00





















  • I'm guessing the browser will allow you to download whatever is playing. Wouldn't that be preferable? The browser will have already cached the audio file, so downloading what's cached and playing seems beneficial.

    – Brad
    Nov 28 '18 at 3:23











  • @Brad I get what you're saying, but the main issue is that if the browser is playing the .opus audio file, then right clicking and selecting "save audio as" will download the .opus file. From my experience, not many people would know how to deal with .opus audio files.

    – origamifreak2
    Nov 28 '18 at 13:00



















I'm guessing the browser will allow you to download whatever is playing. Wouldn't that be preferable? The browser will have already cached the audio file, so downloading what's cached and playing seems beneficial.

– Brad
Nov 28 '18 at 3:23





I'm guessing the browser will allow you to download whatever is playing. Wouldn't that be preferable? The browser will have already cached the audio file, so downloading what's cached and playing seems beneficial.

– Brad
Nov 28 '18 at 3:23













@Brad I get what you're saying, but the main issue is that if the browser is playing the .opus audio file, then right clicking and selecting "save audio as" will download the .opus file. From my experience, not many people would know how to deal with .opus audio files.

– origamifreak2
Nov 28 '18 at 13:00







@Brad I get what you're saying, but the main issue is that if the browser is playing the .opus audio file, then right clicking and selecting "save audio as" will download the .opus file. From my experience, not many people would know how to deal with .opus audio files.

– origamifreak2
Nov 28 '18 at 13:00














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418809%2fhtml5-audio-element-multiple-source-download-preference%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418809%2fhtml5-audio-element-multiple-source-download-preference%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()