我正在为我的覆盆子pi制作音乐播放器。 它是从我的列表中的字符串中删除'/ home / pi / Desktop / Muziek /'。但我一直收到此错误:
Traceback (most recent call last):
File "/home/pi/Desktop/Music Player(Alpha2.2).py", line 19, in <module>
pygame.mixer.music.load(SongPath + Song[0])
error: Couldn't open ' Toto - Africa.mp3'
>>>
我认为这是因为'和托托之间的空间,但我不知道如何解决它。 BTW这里是代码:
import glob
Song1 = glob.glob('/home/pi/Desktop/Muziek/*.mp3')
Song2 = glob.glob('/home/pi/Desktop/Muziek/*.ogg')
Song = Song1 + Song2
Song = [s.strip('/home/pi/Desktop/Muziek/') for s in Song]
Song = [s.replace('/home/pi/Desktop/Muziek/','') for s in Song]
SongPath = '/home/pi/Desktop/Muziek/
print('Music Player(Alpha2.2)')
import pygame
from time import sleep
Song = sorted(Song)
CurrentSong = 0
State = 'Playing'
pygame.mixer.init()
pygame.mixer.music.load(SongPath + Song[0])
pygame.mixer.music.play()
print("Songs:")
for i in range(0, len(Song)):
print(i+1, Song[i])
print('\nStarted auto play on:\n' + Song[CurrentSong])
答案 0 :(得分:0)
我使用os.listdir('')而不是glob。