I need to find out default file opener for a given file on Windows so that I can customize the command arguments and open the file with the default opener/viewer.
My real usage scenario is opening multiple multimedia files with user's default media player so that all the files will be added to user's playlist (For the players that can open multiple files on the same intance). For operating system other than Windows I use Desktop.open(File file)
method (I simply does not concern opening multiple files feature for OSs other than Windows), I cannot find any method which I can open multiple files other than customizing command arguments and running it using exec() method of the Runtime class. I use somethig similar to this:
private void playItems2(List<File> fileList, String playerBinary) {
String args = " ";
for (File file : fileList) {
args += "\"" + file.getAbsolutePath() + "\" ";
}
try {
String command = playerBinary + args;
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(command);
} catch (Exception exc) {/*handle exception*/
System.err.println("Run Player Exc:" + exc.getMessage());
}
}
I am using user specified path for the playerBinary
, what I need to is automatically detecting default player for the first item of fileList
and use it as playerBinary
.
I have also looked at Rundll32.exe and cmd.exe /start solutions but they did not work for my usage scenario.