3

I'm working on a Windows Form Application in which I have embedded a Windows Media Player that lets you play video files. The unique thing is that I have changed the extension of the media files (for reasons which I can't get into here). For instance, "xyz.wmv" might be called "xyz.ext". They play just fine, but before they play, I get the message:

"The file you are attempting to play has an extension that does not match the file format. Playing the file may result in unexpected behaviour. Do you want the Player to try to play the file?"

You can click yes and you can even check the box to not show that message again, but I don't want that for all the obvious reasons including the fact that it confuses users. I have looked into the .settings properties but I cannot find a way to suppress this message and more importantly other messages that might come up.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Chiwda
  • 1,233
  • 7
  • 30
  • 52
  • OK, I got as far this code: Private Sub wmpPlayer_Warning(sender As Object, e As _WMPOCXEvents_WarningEvent) Handles WMPlayer.Warning MsgBox(e.warningType.ToString) But the message appears and this code is not reached at all... End Sub Private Function wmPlayer_Warning() As Object Throw New NotImplementedException End Function – Chiwda May 12 '13 at 17:15
  • @abcdefghi: The bounty question is unrelated. Ask separately to get the answer. – Roman R. Sep 27 '13 at 15:28
  • @RomanR. Seem to be pretty much the same question to me with the exception that he wants to handle it in code. Also - the answer I gave should already solve it, unless I am mis-interupting the question? I agree I would have re-asked and linked to this question, but the bounty is already set... – Matthew Sep 27 '13 at 16:37
  • 1
    @Matthew: Bounty and original question have close to zero in common. To add to this, this is the second edit of a question with unrelated bounty this week from the same user, so I find it simply impossible and incorrect to go into details on the question itself. – Roman R. Sep 27 '13 at 16:47
  • I've gone ahead and removed the bounty, as well as rolling back the extreme edits. That's not how bounties are supposed to be used. – Brad Larson Sep 30 '13 at 19:20
  • I am going to leave my answer to the bounty question as I think it adds some relevant detail to the OP as well. – Matthew Oct 01 '13 at 05:11
  • Sorry about the Bounty confusion. I must have clicked some wrong option. I have never (successfully) used a bounty, so I will have to read up on this. I have been meaning to do this for a year now, but haven't gotten around to it. :-P Any pointers? – Chiwda Dec 09 '14 at 12:26

2 Answers2

3

The .ext (for example) extension is not known to media player, hence the warning.

What you can do to change this is modify the registry and register this extension. This is described officially here: File Name Extension Registry Settings

The most simple way to do it is to create a registry key like this:

HKEY_CURRENT_USER\Software\Microsoft\MediaPlayer\Player\Extensions\.ext

And add two key values:

Runtime (DWORD): 6
Permissions (DWORD): 15 (or 0xF in hexa)

This is shown here:

enter image description here

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • The extension is already registered to my application. However, the Windows Media Player is embedded within my application. I pass the filename to the player and it gives me the warning described above. Obviously I don't want register the extension in two places... – Chiwda May 13 '13 at 11:53
  • With my answer, I don't have any more warnings with an embedded media player, have you tried it? – Simon Mourier May 13 '13 at 11:55
  • I am quite sure you are correct in that the message will go away. And thank you for that solution. However, there are two concerns. First, I don't know if and how it will affect my file association that is registered to my application. Second, I do want to find a generic answer so I can manage warnings and errors in general. I will of course try your solution, but I don't want to rush into the registry - it always creates Fear & Dread for me. :-) – Chiwda May 15 '13 at 08:13
  • OK, it worked and it appears to have not affected my file association. I am going to wait and see if I can get a more generic solution as described above, otherwise I will accept your answer. – Chiwda May 15 '13 at 09:17
  • P.S. is there a explanation/reference somewhere on what the values for the DWORDs mean? – Chiwda May 15 '13 at 09:26
  • Read my answer, there is a link for this. – Simon Mourier May 15 '13 at 09:31
0

NOTE: this answer was originally in response to a bounty question and edit which was removed on how to do this via code. Parts of this are still relevant to the original question.

You can do this pretty straight forward IF you have admin rights as you need to edit the registry. Not sure how far you will get without admin rights and can test later, but here is how to do this via code (in a real implementation I would do this as part of a setup - or check if the keys exist each time which seems wasteful):

You need to add one key (showing two here for registering the extensions, you may need additional keys for auto-play or a setting on the player):

private void Form1_Load(object sender, EventArgs e) {
 /*This first key is not necessary - and if you will be using common 
  * extensions like mp4, skip this step altogether!! 
  */
 RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", true)
                                       .OpenSubKey("Classes", true);
 key.CreateSubKey(".myExt");
 key = key.OpenSubKey(".myExt", true);
 key.SetValue("", "WMP11.AssocFile.myExt");
 key.SetValue("Content Type", "video/x-ms-wmv");
 key.SetValue("PerceivedType", "video");

 /*Here is the magic key which will make the dialog go away*/
 key = Registry.CurrentUser.OpenSubKey("Software", true)
                           .OpenSubKey("Microsoft", true)
                           .OpenSubKey("MediaPlayer", true)
                           .OpenSubKey("Player", true)
                           .OpenSubKey("Extensions", true);
 key.CreateSubKey(".myExt");
 key = key.OpenSubKey(".myExt", true);
 key.SetValue("", "");
 key.SetValue("Permissions", 0x20);

 axWindowsMediaPlayer1.URL = @"C:\Users\Public\Documents\Wildlife.myExt";
}

Media Player creates other keys when you add through its dialog, but the only one definitely needed is: HKEY_Current_User.Software.Microsoft.MediaPlayer.Player.Extensions

If you want to see all the keys Media Player adds,

  1. choose a crazy extension,
  2. click always allow when prompted and then
  3. search the registry for all the keys that get created.

The above code is tested and working for me - confirming the dialog before adding the keys and the lack of any dialog after.

This is a good generic process for programmatically adding file associations and default programs to the Windows Registry from .NET. You have to be careful about registering the extension (the first key I set above) IF the extension already exists (TEST FOR THIS). Otherwise the above code will happily overwrite your current values. All you really should need is the one added to: HKEY_Current_User.Software.Microsoft.MediaPlayer.Player.Extensions anyway. Think it through, check in advance, and test before you go crazy in the registry!!

It is also always a great idea to backup your registry before playing with it.

Final note: missed your question on how to reproduce once you have clicked always allow: just remove the entry in HKEY_Current_User.Software.Microsoft.MediaPlayer.Player.Extensions and voila!

This answer assumes you have a working knowledge of regedit.

Final note #2: Response geared to the questions in the Bounty. Other errors can be suppressed by setting telling Media Player to allow you to handle error events and then writing your custom handler. I have not done this before so cannot comment on the ease and what can/cannot be controlled through this method.

The Windows Media Player control does not raise an exception when it encounters an error such as an invalid URL. Instead, it signals an event. Your application should handle error events sent by the Player.

These can then be handled by creating / registering a MediaError event:

    private void axWindowsMediaPlayer1_MediaError(object sender, AxWMPLib._WMPOCXEvents_MediaErrorEvent e) {
           // Handle errors and profit!
    }

Then set this as the handler in the Events property window for your control - same for other events such as ErrorEvent.

Matthew
  • 9,851
  • 4
  • 46
  • 77
  • @abcdefghi - You might be ok with editing the registry as it is manipulating `Current_User`. If not you will need to get admin privledges to add, but if the media player dialog worked without asking for admin rights you should be ok. If not - at least you will be able to create a dialog with your own message. – Matthew Sep 26 '13 at 16:12
  • Your answer is [supposedly] in good standing. And abcdefghi's question was not really related. It was about a special case of misbehaving filter which pops up blocking UI where it is not expected, and there are special filter-specifica ways to avoid it: an application can add it onto filter's blacklist, an application (not WMP though) can reject this component to be not used at all, finally an application might use a hook to prevent from this behavior. The edit was not really related much to helping WMP match file and registration together. – Roman R. Oct 01 '13 at 14:45