Sep-09-2019, 05:50 PM
Hi,
The following code plays a mp3 file from a folder randomly. After few days running, it stops but I just cannot find the problem/cause. What king of checks should I add into the code to trap the culprit line?
TIA
The following code plays a mp3 file from a folder randomly. After few days running, it stops but I just cannot find the problem/cause. What king of checks should I add into the code to trap the culprit line?
TIA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
#!/usr/bin/python3 from __future__ import print_function import random, os import pygame import logging #music files path path = "/media/usb/" #get music files songs = os.listdir(path) #filter mp3 files songs = [fi for fi in songs if fi.endswith( ".mp3" )] pygame.init() pygame.mixer.init() #print(pygame.mixer.get_init()) def play_songs(): try : #pygame.mixer.music.set_volume(0.50) filename = random.choice(songs) #print('playing now {}'.format(filename)) pygame.mixer.music.load(path + filename) pygame.mixer.music.play() while pygame.mixer.music.get_busy(): pygame.time.Clock().tick( 10 ) except ValueError: logging.exception( "msg from music.py: " + format (ValueError)) print ( 'Excemption: {}' , format (ValueError)) if __name__ = = '__main__' : while True : play_songs() |