Reputation: 2186
I am trying to play a video in Windows media player through my code. The path is:
C:\Program Files (x86)\Windows Media Player\wmplayer.exe
If I hardcode it,
string filePath = System.IO.Path.Combine (Application.streamingAssetsPath, "Demo.mp4");
Process proc = new Process();
proc.StartInfo.FileName = @"C:\Program Files (x86)\Windows Media Player\wmplayer.exe";
proc.StartInfo.Arguments = "\"" + filePath + "\"";
proc.Start ();
I can play the video. But I want to use the path which is universal for all the machines. So after going through this link Programmatically detect if Windows Media Player is installed, I re-wrote my code to:
private string makePath;
RegistryKey myKey;
makePath = @"HKLM\Software\Microsoft\Active Setup\Installed Components\{22d6f312-b0f6-11d0-94ab-0080c74c7e95}";
myKey = Registry.LocalMachine.OpenSubKey (makePath);
IEnumerator Example ()
{
if (myKey == null) {
print ("No Windows Media Player Installed");
} else {
proc.StartInfo.FileName = makePath;
proc.StartInfo.Arguments = "\"" + filePath + "\"";
proc.Start ();
}
and calling this function somewhere But then myKey appears to be null. Is the path correct which I have mentioned here or what have to be made in order to get the video played?
Upvotes: 0
Views: 2837
Reputation: 5264
On 64-bit Windows, portions of the registry entries are stored separately for 32-bit application and 64-bit applications and mapped into separate logical registry views using the registry redirector and registry reflection, because the 64-bit version of an application may use different registry keys and values than the 32-bit version.
Here is an example of how to access the 32-bit view of the registry. Specifies which registry view to target on a 64-bit operating system use RegistryView.
Use this
var view32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
RegistryView.Registry32);
using (var clsid32 = view32.OpenSubKey(@"Software\Microsoft\Active Setup\Installed Components\{22d6f312-b0f6-11d0-94ab-0080c74c7e95\}", false))
{
// actually accessing Wow6432Node
}
Upvotes: 0
Reputation: 612804
The reason you cannot find that registry key is that you are running a 32 bit process on a 64 bit system. And so the registry redirector comes into play. The code will attempt to resolve the registry key under the Wow6432Node
.
Solve the problem by using the RegistryView
enumeration to specify that you want to look in the 64 bit view of the registry. Or run as a 64 bit process.
FWIW, it might just be simpler to let the shell decide (using the user's file associations) which program to use to play the video.
Upvotes: 2