Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get default media player name of the OS?

 
Minh Nam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Minh Nam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5406
52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can download the file first, save it in some temporary folder and then pass it to the Desktop class.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm with Stephan. What if the default player doesn't support playing media from URLs?
 
Minh Nam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic