2017-04-16 2 views
-3

이 코드를 실행하려고하는데 다음 오류가 발생합니다. Error : AudioFileOpen failed ('wht?'). 그 어떤 도움 경우 그래서 여기 내 코드는 - 그것은 맥과 MP3 파일의 폴더와 실행중인 것 :파이썬 - 'Error : AudioFileOpen failed ('wht? ') 의미는 무엇입니까?

어떤 도움을 환영 크게 귀하의 질문에서
+0

아마'playMusic()'에서 온 것일 수 있지만 그 기능이 무엇인지 알 수있는 방법이 없습니다. 확실히 표준 라이브러리가 아닙니다. – Chris

답변

0

(이에서보세요 감사한다
import os 
def randomShuffleSongFromFolder(folderPath): 
    try: 
     music = os.listdir(folderPath) 
    except: 
     print('Error-Music folder not found') 
     exit() 
    random.shuffle(music) 
    music.remove('.DS_Store') 
    print(folderPath) 
    print(music) 
    for song in music: 
     os.system('afplay "' + song + '"') 
if __name__ == '__main__': 
    print(os.listdir('/Users/isaac_lims_macbook_air/Desktop/davidMusic')) 
randomShuffleSongFromFolder('/Users/isaac_lims_macbook_air/Desktop/MusicExample/') 

) :

for song in music: 
    os.system('afplay "' + song + '"') 

music에 포함 된 내용을 기억 : 파일 이름 목록 (예 : "Adele - Hello.mp3"). . 당신은 당신이보고있는 디렉토리를 이야기하지 않는 afplay에게 전달하는 경우 (오류 메시지가 파이썬에서 오는되지 않습니다, 오히려 afplay 자체에서, 예를 들어 this other question where the same command is called from C를 참조하십시오.)

포함 os.path.join()를 사용해보십시오 디렉토리, 예.

import os.path 

# Assuming folderPath is being passed into the containing function as above 
for song in music: 
    songPath = os.path.join(folderPath, song) 
    os.system('afplay "{}"'.format(songPath)) 

이렇게 afplay"/Users/you/Desktop/Music/Adele - Hello.mp3" 같은 절대 경로를 수신한다.

관련 문제