user1909680
user1909680

Reputation: 95

Open mp3 file using specific applications java

I want to know if there is a way of opening mp3 files using either Windows Media Player and VLC Media Player. I have the path of the file saved as a String and was wondering if I can use this to open the file on either of the applications mentioned above. I understand one method of doing this is by using the Desktop class but this opens the file using the default application, which is Windows Media Player in my case. How would I open the file in VLC media player?

Upvotes: 1

Views: 1960

Answers (3)

linski
linski

Reputation: 5094

Judging by the Desktop.open apidoc and Desktop tutorial it looks like the open method can only open the file in their default associated program.

So, you have (maybe) two options here:

  • access the registry and change the default association (not a nice one)
  • might try giving a URI and opening it via browser, which might result in opening the file in desired program. However, it looks like the file scheme is the only acceptable solution, and that will most probably open in the default program. There is a mms scheme but it is used for video-streaming, and again, it will most probably open in the default program.

Here is a link to the Runtime.exec solution for windows, linux and osx variant.

Upvotes: 1

Ostap Andrusiv
Ostap Andrusiv

Reputation: 4907

You should know the path to the VLC and/or WMP. Then you can use Runtime class for this.

Process p = Runtime.getRuntime().exec("c:/vlc/vlc.exe " + mp3FileName);

Upvotes: 0

BackSlash
BackSlash

Reputation: 22233

try

Runtime.getRuntime().exec("<your vlc path> <your file>");

I.E.

Runtime.getRuntime().exec("\"C:\\Program Files (x86)\\VideoLAN\VLC\\vlc.exe\" abc.mp3");

Tried and it works

Upvotes: 2

Related Questions