检测窗口的默认媒体播放

2024-06-08 07:22:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试检测Window的默认媒体播放器路径,以便可以从Python/wxPython程序访问它。我的具体需要是列出所有的媒体文件,并用播放器播放。在


Tags: 路径程序wxpythonwindow播放器媒体播放器媒体文件
1条回答
网友
1楼 · 发布于 2024-06-08 07:22:34

根据上面的评论,看起来你决定朝另一个方向发展。你的问题让我很好奇,所以我四处打猎。

文件关联存储在Windows注册表中。通过python访问Windows注册表信息的方法是使用_winreg模块(在2.0和更高版本中可用)。当前用户的单个文件关联信息将存储在名为以下名称的子项中:

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用于您要查找的任何特定文件格式。

下面是我编写的一个小示例脚本,用于访问此信息并将其存储为列表:

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

输出:

[u'WMP11.AssocFile.WMV', u'WMP11.AssocFile.avi', u'WMP11.AssocFile.MPEG']

使用WMP11=Windows Media Player 11

希望这对你有帮助。

资料来源:

{a2}

相关问题 更多 >

    热门问题