Media Player Window Detection

I am trying to determine the default path of a Windows media player in order to access it from my Python / wxPython program. My special need is to make a list of all media files and play them using the player.

+3
source share
1 answer

Based on the comments above, it looks like you decided to go the other direction with this. Your question aroused my curiosity, although I still hunted around.

File associations are stored in the Windows registry. The way to access Windows registry information through 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 in subsections 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. for any particular file format you are looking for.

Here is a small example script that I wrote to access this information and saved 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

Conclusion:

[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

+2
source

Source: https://habr.com/ru/post/1785626/


All Articles