I'm trying to detect Window's default media player path so that I can access it from my Python/wxPython program. My specific need is to make a list of all media files and play it using the player.
Based on the comments above, it looks like you decided to go in another direction with this. Your question made me curious though so I did some hunting around anyway.
File associations are stored in the Windows Registry. The way to access Windows Registry information via python is to use the _winreg module (available in versions 2.0 and later). Individual file association information for the current user will be stored at subkeys named as follows:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.wmv\UserChoices
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mpeg\UserChoices
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.avi\UserChoices
etc, etc for any specific file format you are looking for.
Here is a small example script I've written to access this information and store it as a list:
import _winreg as wr
# Just picked three formats - feel free to substitute or extend as needed
videoFormats = ('.wmv', '.avi', '.mpeg')
#Results written to this list
userOpenPref = []
for i in videoFormats:
subkey = ("Software\\Microsoft\\Windows\\CurrentVersion" +
"\\Explorer\\FileExts\\" + i + "\\UserChoice")
explorer = wr.OpenKey(wr.HKEY_CURRENT_USER, subkey)
try:
i = 0
while 1:
# _winreg.EnumValue() returns a tuple:
# (subkey_name, subkey_value, subkey_type)
# For this key, these tuples would look like this:
# ('ProgID', '<default-program>.AssocFile.<file-type>', 1).
# We are interested only in the value at index 1 here
userOpenPref.append(wr.EnumValue(explorer, i)[1])
i += 1
except WindowsError:
print
explorer.Close()
print userOpenPref
Output:
[u'WMP11.AssocFile.WMV', u'WMP11.AssocFile.avi', u'WMP11.AssocFile.MPEG']
with WMP11 = Windows Media Player 11
Hope this was helpful.
Sources:
python docs, effbot tutorial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With