How to open local audio file in new tab and play with default player - javascript/jquery/html

Reply Tue 15 Apr, 2014 02:13 am
I need to open audio mp3 or other audio format file in new tab. File path is local system like file:///home/path_to_mp3/xyz.mp3. I am not uploading files on sevrer.

Audio file should play default player like windows media player, VLC player or whatever is installed in PC.

I tried it like this:

<a href="file:///home/path_to_mp3/xyz.mp3" target="_blank"> click to play </a>

It's working fine for ms-word, text or other format files, but not working for audio.

I am using ruby on rails.
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 3,221 • Replies: 5
No top replies

Peter Frouman
Reply Tue 15 Apr, 2014 06:05 pm
I suggest you check the browser plugin settings for audio files and make sure that the linked to MP3 file exists in the specified location. I tested this (using a valid local path) in Chrome (Linux) and it worked as expected (opened a new tab playing audio file using Totem plugin) but what happens when the user clicks the link will vary depending on browser settings. If you have sufficient access to place the file in a specific location using an absolute local path, you should have enough access to change the browser settings to do what you want.
Reply Thu 17 Apr, 2014 03:47 am
@Peter Frouman,
I don't have any plugin installed and didn't find any chrome setting. Should I install any plugin?
Peter Frouman
Reply Thu 17 Apr, 2014 12:10 pm
It's up to you whether you want to install a plugin or not. You don't necessarily need one if you have an external application that will play the file.

For Chrome you find a list of plugins at chrome://plugins/

You can also go to chrome://settings/, click on show advanced settings and then "Content settings..." under the Privacy menu.

There you can select whether plugins run automatically, require a click to play or are blocked.
Reply Thu 17 Apr, 2014 02:05 pm
@Peter Frouman,

I don't want to install plugin. How can I play audio. What settings I need to do.

Many thanks

- Raj
Peter Frouman
Reply Fri 18 Apr, 2014 02:46 am
Since the audio file is a local filesystem path and thus you can't send server headers (like Content-disposition and Content-type) with it, your options to force a download are somewhat limited.

I assume you are using Chrome. Apparently, there is no way to easily disable the built-in audio player in Google Chrome but you still have a couple options to play the file without a plugin:

1. Right-click the link and choose "Save as..." from the menu. Then click on the file from the Downloads toolbar or window and it should play using whatever the default external application is for that file type

2. Use the HTML5 download attribute to force download. This will only work on browsers that fully support HTML5 - mostly newer versions of Firefox, Chrome and Opera

<a href="file:///local/path/to/file/StraightOuttaCompton.mp3" download="StraightOuttaCompton.mp3">download file</a>
0 Replies

Related Topics

  1. Forums
  2. » How to open local audio file in new tab and play with default player - javascript/jquery/html
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 04/19/2024 at 04:46:46