This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes how to get default media player name of the OS? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "how to get default media player name of the OS?" Watch "how to get default media player name of the OS?" New topic
Author

how to get default media player name of the OS?

Minh Nam
Ranch Hand

Joined: Sep 10, 2011
Posts: 57
Hi guys,

I am wondering how to get the default media player name (and its full path if possible) on the target operating system?

For example, if Windows Media Player is the default on Windows, the program will return "wmplayer.exe",... something like that.

I need you help and suggestion.

Thanks.


Advanced java topics
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

There is no such thing as the default media player. There are default applications for file types, and the OS has a mapping for media file types to what you call the default media player. However, it's quite possible to have one media player for one media file type and another media player for another media file type.

If you want to open a file in the default application, you should check out java.awt.Desktop and its open method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Minh Nam
Ranch Hand

Joined: Sep 10, 2011
Posts: 57
Rob Spoor wrote:There is no such thing as the default media player. There are default applications for file types, and the OS has a mapping for media file types to what you call the default media player. However, it's quite possible to have one media player for one media file type and another media player for another media file type.

If you want to open a file in the default application, you should check out java.awt.Desktop and its open method.


Thanks for your quick reply. okay, it is the default application that I want to mean.
So how to get the name of the default application that is going to open my file?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

You will need to access the Windows registry, or the appropriate configuration files on Linux / Mac OS (no idea which ones).

But why do you need it? If you need to open a file with its default application you should use java.awt.Desktop as I already suggested.
Minh Nam
Ranch Hand

Joined: Sep 10, 2011
Posts: 57
Rob Spoor wrote:You will need to access the Windows registry, or the appropriate configuration files on Linux / Mac OS (no idea which ones).

But why do you need it? If you need to open a file with its default application you should use java.awt.Desktop as I already suggested.


I need the name of the application to pass the URL as an argument to it, because I want to play a video from a URL.
The java.awt.Desktop's open method works nicely with local file, but for URL it opens a browser window which is not what I expect.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3605
    
  14

You can download the file first, save it in some temporary folder and then pass it to the Desktop class.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

I'm with Stephan. What if the default player doesn't support playing media from URLs?
Minh Nam
Ranch Hand

Joined: Sep 10, 2011
Posts: 57
Stephan van Hulst wrote:You can download the file first, save it in some temporary folder and then pass it to the Desktop class.


I thought like you before, but the problem is the video file is usually big and it takes a while to be downloaded, whilst the media player can buffer and play the media without need to download the whole file first.
 
 
subject: how to get default media player name of the OS?
 
Similar Threads
Reading an mp3 file
how to open a file using default program
problem embedding Media Player object for Firefox
play wav in Windows Media Player
Executing files....mp3 style