2011-01-15 2 views
3

윈도우의 기본 미디어 플레이어 경로를 감지하여 파이썬/wxPython 프로그램에서 액세스 할 수 있습니다. 내 구체적인 필요는 모든 미디어 파일의 목록을 만들고 플레이어를 사용하여 재생하는 것입니다.윈도우의 기본 미디어 플레이어 감지

+2

내 조언은 시스템의 내부 세부 사항을 발견하려고 노력하지만, 무엇 이건 시스템 "열기"파일을 만들기 위해'os.system'를 사용하지 않는 것입니다 그것은 적절한 응용 프로그램이라고 생각합니다. – ulidtko

+0

글쎄, 그건 간단했다. 감사합니다 :) – spitfire

+0

경우에만 경로에 공백이있을 때 실패하는 문제입니다. – spitfire

답변

2

위의 설명에 따르면, 이와 함께 다른 방향으로 가기로 결정한 것처럼 보입니다. 귀하의 질문에 호기심이 생겨서 어쨌든 주위에서 사냥을했습니다.

파일 연결은 Windows 레지스트리에 저장됩니다. 파이썬을 통해 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

등, 등.

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 

출력 : WMP11 = 윈도우 미디어 플레이어 11

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

여기

내가이 정보에 액세스하고 목록으로 저장하기 위해 작성한 작은 예제 스크립트입니다

희망이있었습니다.

출처 :

python docs, effbot tutorial