nakiya
nakiya

Reputation: 14423

How do I find out if there is a player present in computer which can play a given file format?

1.There are some file formats (suppose a real audio file? (.ra)) which VLC can play butWindows Media Player (Default) can't. How can I find out if there is a player in the system that can play the file format I want?

2.Additionally, is there a way to embed such a player in my (C#) application in a generic way?

Upvotes: 0

Views: 106

Answers (1)

Pavel Donchev
Pavel Donchev

Reputation: 1899

It is a bit complicated but I can give you a start point (the code would be a bit too long to write it now), so here is what I think.

You just go and search in the

HKEY_CLASSES_ROOT 

hive for the extension of the file (in your case it will be .ra). If you find such key, you will either have a subkeys that will help you determine what software has been used to open them or using the "Content Type" string value, you perform another search in the HKEY_CLASSES_ROOT where you will again have keys that will say what software opens this kind of content.

So you need to use the classes that deal with the Registry (asuming you want to do this programatically).

About your second question: I don't think there is a generic way to embed any player in your application. It's because not every player will provide some API to attach to, you won't have a contract to rely on and a lot of other problems. You may have some success with the Windows API but I doubt it will cover all the scenarios you will end up having to support.

You have few choices here:

  1. Do everything you can with Media Player and if the file format is not supported - offer the user to open it with the default player (simple call to the System.Diagnostics.Process.Start with the filename should be enough for Windows to start the appropriate program) (easiest approach).
  2. Write your own player, which can read / transform from various formats. You should be able to find a lot of the formats supported by different libraries in Internet or at least find their RFCs (the most tough you can do).
  3. Use some library or software to convert the file types you cannot play in the background and run them with the media player as if they were supported (probably a good way to achieve maximum result with minimum efforts), you can again fire some processes in the background with the System.Diagnostics.Process.Start, hiding them from the user and load the media after it was converted. Video sites like YouTube do something like this when you upload a file - they put it on another process so it can be converted and then the video is available in common format (in most cases it is flash video - flv, I believe).

Upvotes: 2

Related Questions