سؤال

I'm trying to set up a local media server, purely for educational purpose, and want to open local video files in VLC media player via the browser (preferably Chrome)

So far I've tried the following without any luck:

local "file:///" URLs: was able to open local directories in windows explorer but no luck opening media files in their designated programs (using IE11).

This works if run via command line (php my_file.php), but not via browser:

$file = 'pathToFile';
system("pathtovlc/vlc {$file}");


Running a .bat file via PHP that in turn calls the VLC command line doesn't work either

In the end, opening files directly via the command line, or using PHP via the CLI, works like a charm but I havent found a way to open a file successfully via the browser.

I'm assuming it's a user permission issue as the apache service is run using system permissions, but I can't seem to find a workaround for this. I read about running the apache service with administrator permissions but I'm not able to find how to actually pull this off..

Any input is greatly appreciated!

== EDIT ==

I tried to run a VLC command through psexec, but no luck..the command was run like:

exec('path_to\psexec -u myUsername -p myPassword -c ^path_to\vlc.exe 
path_to\media_file');

Again this works great via command line, but not via the browser..

== EDIT 2 ==

Still fiddling around with this as there's bound to be a way to open media files in their designated program from within a webbrowser.

Apache now has administrator rights but still no luck getting this to work!

== EDIT 3==

I fiddled around with the locallinks extension in Chrome and Firefox and this got me a bit further. Opening <a href="file:///path">link</a> links by simply clicking on it did work in Chrome, but resulted in the problem of chrome ALWAYS downloading files (even if they're local) instead of just opening them in their designated program.

For firefox, the extension worked but it requires a right click -> locallinks -> open, which seems ok but I'm really looking for a one click solution.

Opening a file directly (say an .mkv file) in VLC works perfectly fine in Firefox via a local .html file, but when served over http://. I changed Firefox's security.fileuri.strict_origin_policy setting in about:config to false, which allows me to open local file:/// URL's even via HTTP, but for some reason it strips the filename from the end of the file URI which means it points to the directory the file is in and not the file itself.. frustrating to say the least

هل كانت مفيدة؟

المحلول

In the end I got it working (solely on firefox) in a way that I can click a file URL, and the file is opened outside of firefox in the designated program.

Turned out that setting the security.fileuri.strict_origin_policy setting to false, capability.policy.default.checkloaduri.enabled to allAccess and disabling firefox's vlc plugin was all there was to it!

I still haven't found a crossbrowser solution, not even with commands executed via PHP on an administrator level, but I kind of gave up hope!

نصائح أخرى

I don't know about JS (pretty sure you can't do that natively for security reasons), but since you specified that you are running it locally, you can do that in PHP:

$vlc = "C:\Program Files (x86)\VideoLan\VLC\vlc.exe"; // or whatever the path to vlc is;
$path_file = "C:\your\path\file.mp4"; // you can also retrieve that with a relative path like using realpath(relative_path);

// launch vlc
pclose(popen("start \"$vlc\" \"$path_file\"", "r"));

If you want to open all files in a folder you can do that:

pclose(popen("start "VLCFlux" \"$vlc\" \"$path_folder\"", "r"));

Coupled to an ajax call to execute this script, there isn't much difference.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top