Open file in VLC from a href="path/of/file..WAV" - javascript

I'm looking a way to open a .wav49 on VLC with a link from my web app. Since files with .wav49 are not supported by <audio> tags. And I can't change the file type to a normal .wav or .mp3 due to several reasons.
The audio files are located in a shared folder on my server (which is a Windows Server 2016), so everyone on our network can access them.
The goal of my app is to make the audio file searching something easy.
I've been looking for options like change the format in backend and stream a .mp3 file to the audio tag or a plugin that allows to play .wav49 files but it seems that the easiest way is just to send the file to be opened on VLC.
The only I have for now is this
<a href="file:\\CENTRAL\path\audio.WAV">
I also tried with
<a href="file:\\CENTRAL\path\audio.WAV" download="test">
But neither works.
Only in Firefox, when I click the link ask me if I want to save it or just open it, but both of the options download the file. I don't want to download the file, I just want to launch an alert asking if the user wants to launch VLC and open the audio.
There are some examples of what I want to do, like roblox.com when a user click on the play button and he has the app installed, the browser launch the app on the local machine and gives the params of the game the user wants.
Another example is comodo remote control, when an user of comodo is in the web device manager and wants to begin a remote session, the user just click a button and an alert appears asking if the user wants to launch the remote control by Itarian app, if the user says yes, the app is launched in the local machine.
I found this Open video stream on VLC Player through the browser but it seems doesn't work anymore.

First of all, the standard path separator to be used here is a forward-slash, also if you want to link to a local file you need to use the file:/// prefix with three slashes. For network shares you would use two slashes: file://smbhost/path
So i would recommend you try the following:
<a href="file://CENTRAL/path/audio.WAV">
Hope this helps

Related

Cannot open a local file from webpage

I want to open files from webpage. For example when we try to download a torrent file it redirects us to utorrent app and it continues it work. I also want to open a local file somehow using OS software. Like a video file using pot player. Is there any possible solution for me ,like making a autorun in pc to run that . Anything it may be please help me.😔😔
I searched and found a solution to open a software using protocol, but in this way I cannot open a file in that software.
Opening a specific file in a specific software would usually depend on passing some URL parameters to the protocol-URL of the app (e.g., opening a file in VSCode would use a URL like vscode:///Users/me/file.html, but this functionality would have to be explicitly handled by the app itself though, so the solution for each app would be different).
Otherwise, if the app doesn't support opening a specific file itself through a URL, you'd have to use some scripting software (e.g. AppleScript if you're on macOS) to dynamically click/open certain programs on a user's computer.
the link acts as a magnet so your torrent application is opened maybe delete torrent for sometime till you finish the project, i know how to open image in local files in html but it will only be visible to you, you can do audio and video files also using <source src="movie.mp4 and on next line `type="video/mp4">

Is it possible to programmatically cancel/stop a started download from JavaScript?

Our application implements a custom download manager.
So actually this means that when a user starts a download of a resource he/she has the opportunity to cancel it through a UI button from the app, which actually sends some event to the server to cancel the downloading (the connection is disconnected and etc).
But since recently Chrome added auto-resume of failed downloads, so the same request is resumed to be downloaded again from the Chrome Download Manager, it's because Chrome cannot distinguish that the user/server intentionally canceled the HTTP connection so it revokes it again.
Currently, we download resources using IFrame, but once the download is started by the browser changing the IFrame's src attribute is not relevant anymore. I've tried to use <a href='...' download> but the issue is the same.
Maybe there's some API at least for Chrome? (There's actually such for Chrome extensions but this is not the case)
You cannot control the downloads that are managed by the download manager, of the browser.
If you want to control the download then you need to fetch the file JavaScript by e.g. utilizing the Streams API.
After you downloaded the Data you can pass that file to the download manager of the browser.
Each of those tasks can be solved in different ways.
Could you do something like add a unique key to the URL for each download request? When the user cancels the download, you invalidate the key so that the URL cannot be used again to download that resource - and in the process prevents Chrome from being able to resume the download.

Amazon CloudFront - Restrict MP3 to play on specific website

I've been trying figure out how to get mp3 files in an Amazon S3 bucket paired with Cloudfront to allow me to stream the files directly on my site but not allow anyone to take the source URL of the mp3s by viewing the source code of the page and then sharing or leeching the link.
Right now, I am using an html5 mp3 playlist from mediaelements.js and the mp3 file is always in the source code. That's fine, but I want to only allow the mp3 to play on my specific website and if the link gets copied from the source and accessed in a different browser it should show an access restricted error.
I tired to update the cloudfront policy to expire within 30 seconds of the page load, but that will ultimately prevent the files from playing once the 30 seconds is over and if the user didn't play one of the tracks prior to that expiration.
Is there another way to do this without putting a time expiration on the cloudfront links?
I think this is what you are looking for: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-urls-overview.html
Basically you can vend URLs dynamically from your service, and CloudFront will validate signature. You can also set pretty short expiration time to avoid wide distribution of your URL, and restrict IP addresses that might access URL (see Custom Policies section in the referenced document).
It's possible with just few line wizard coding on back-end (private method) ,i prefer to using free tier EC2 instance and configure environment for handle streamable contents for deliver everything clear this way provide a restrict page to someone going to leech or using IDM for donwload your mp3 files.
Example : Grooveshark.com
However still there is some another methods like Owain answer .
Unfortunately, you can't. MediaElements.js may be hosted on your site, but it's being run on the user's computer. So although it looks like they are playing an MP3 via your site, they are actually just downloading a URL from your site and playing it using code running on their computer.
You could write server-side code that went off to S3 and retrieved the MP3 before returning it as if it were a file hosted on your server, but that still wouldn't limit people from copying that link, unless some sort of session were used before returning the file to ensure they're logged in via your site.
But that would mean you can't make use of CloudFront. That's the compromise. Distribute your MP3 via a CDN and improve download performance by hosting the file in an edge location closer to your users, or take advantage of server-side security to ensure your IP isn't hosted by unscrupulous third parties.

Javascript local file saving or onSave event to get saved filename

I'm developing a web app that needs some sort of filesystem access. Ideally I'd want to be able to "Open..." a file into the app and then "Save" the file back to local filesystem at the location that the user opened it from.
Currently, we use a java applet to achieve this functionality, but since java is going out of style, we're needing to do this with javascript and html5.
Obviously, this can't be done because of security reasons built into browsers, so I'm trying to somewhat emulate it.
I'm using the html5 file api to successfully import/open the files, so that's half the battle. The hard part is getting the saving feature. I'm getting close using an iframe and content-disposition, but problems arise when browsers are set to automatically download the files to a downloads folder... users may get confused and be unable to locate the file they just downloaded.
So, my question is this: is there some sort of onSave event or some kind of way for the browser's "Save As..." window to return at least the filename that the user saved the file under?
Also, I've looked into the filesystem/fileWriter html5 apis, but from my understanding they're limited to only a sandboxed area of the local filesystem and only available in chrome dev releases.
Any help would be appreciated!
No, there is no way to do that with pure JavaScript. You can manage to trigger a download with data URIs or an iframe with some headers but you can't circumvent the browsers' download managers.
You can either use a Flash or Java applet to handle the saving for you, or ask the user to right click on the link and do save as, then he might be able to choose the destination.
One popular option using Flash is Downloadify.

How do you get a spreadsheet to open Excel instead of a browser window?

If you call javascript window.open and pass a url to a .xls file it open on some machines in the browser window. How can you force it into Excel?
Only the users machine can "force" it into Excel. That said, 99% of the time if you send the correct mime-type and a user has Excel, then it will open in Excel assuming they approve.
And only the server can send the correct mime-type. The document type you pass to a JavaScript window.open call will have no effect on this. In fact, calling window.open will at best just open a superfluous window.
It's best to just link to the document with <a href="foo.xls">. And provided your server is sending a mime-type of application/x-excel or application/x-msexcel this will almost always nudge the browser into opening a new window with the Excel document.
If it's just a static file, and you're using Apache on Linux, check for a file called /etc/mime.types, and ensure that it has the following line in there to associate the .xls file extension with the correct MIME type:
application/vnd.ms-excel xls
I'm guessing the location of that file might vary across systems, but it's in /etc/mime.types on my server which is running RHEL4.
AFAIK you can't do this with JavaScript alone. If you have some sort of scripting language on the server's side you can alter the header to force a download.
Here's a simple tutorial in PHP, but you can easily find one in your favorite language.
You cannot force it into Excel. You can allow the browser to handle it whichever way it is configured to do so, or you can try to force it to download the file and let the user open if from their desktop. To force a download, search for "force download" and your server-side language (PHP, ASP.NET, JSP, etc.)
I don't think you can: you cannot call external programs using Javascript for security reasons. Assuming that the user has Excel installed, you may want to open the new window without the address bar to give the user "the illusion" that the file has been opened with Excel in Internet Explorer.
I wouldn't think this is possible from javascript due to security issues, there would be nothing stopping a rogue webpage from opening dozens of excel/word instances.
Could you not set a hyperlink to the url of the .xls, that way the user would get the usual download prompt to view the file.
Set the http content type to the Excel datatype: application/vnd.ms-excel
You shouldn't need to redirect to a new window, but you will get a popup asking the user to save or open the file.
In relation to (2): I'd worry if a browser could launch an external application and load data into it automatically without user intervention.
This is a setting in each user's browser and not in something that can be set by code. So unfortunately you do not have control of that.
You can not, as it depends on the client machine.
For example on Windows if you want it to always open it with Excel, not in the browser window, you have to open My Computer, Tools, Folder Options, File Types, select the XLS type, and click on Advanced. There are two checkboxes: Browse in same window and Open web documents in place. Uncheck both, close browser window, open it again and try again.
However as I said: it depends on the client, you can not force it.
You can do this using LaunchinIE, an ActiveX Control that will enable HTML pages to start whatever application on the client's machine, without security warnings.
Quote from the site: "At last, web pages can start Word, Excel, or any other corporate application without complaints. Securely."
For this you do have to install the control on the user machine and also add the URL that is allowed to execute local applications to the Windows registry.
Another quote from the site: "To ensure security, LaunchinIE needs to be carefully configured client-side; due to this restriction it's only fit for intranet use."
I use LaunchinIE in our training facility so I can use Internet Explorer as a menu which lets the user choose the machine setup. LaunchinIE then calls a batch script that configures the machine to best support the selected training.
Here are the steps to get this pop-up back when opening a saved Excel file.
Right-Click on the windows [START] button and select Explore to open Windows Explorer window will open.
From the menu select Tools \ Folder Options…
• Choose the File Types tab and scroll down the list of files.
• Left-Click to highlight the XLS Microsoft Excel Worksheet file extension and click on the Advanced button.
In the Edit File Type window, Uncheck the “Browse in same window” option.
Click OK button to accept your changes.
Start a new browser session. The next time you open your Excel spreadsheet in your Inbox, you should be prompted with the following window. Be sure to leave the “Always ask before opening this type of file” as checked. Clicking the Open button should now open your file in Excel.

Categories