Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running files using random
#1
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

#!/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()
Reply


Messages In This Thread
Running files using random - by ebolisa - Sep-09-2019, 05:50 PM
RE: Running files using random - by wavic - Sep-09-2019, 09:40 PM
RE: Running files using random - by ebolisa - Sep-10-2019, 03:25 PM
RE: Running files using random - by wavic - Sep-10-2019, 06:11 PM
RE: Running files using random - by ebolisa - Sep-10-2019, 06:54 PM
RE: Running files using random - by wavic - Sep-12-2019, 11:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Running script on multiple files Afrodizzyjack 1 2,545 May-14-2021, 10:49 PM
Last Post: Yoriz
  Flask files running order TomasAm 0 1,478 Nov-12-2020, 08:22 AM
Last Post: TomasAm
  Random access binary files with mmap - drastically slows with big files danart 1 3,988 Jun-17-2019, 10:45 AM
Last Post: danart
  Multi-processing - problem with running multiple *.py files at the same time Antonio 5 3,895 Sep-12-2018, 01:08 PM
Last Post: volcano63
  Running multiple files Totalnoobwithhelp 3 3,444 Jul-18-2018, 09:22 PM
Last Post: Vysero
  Running a python tool transforming xml files into epub files silfer 7 5,482 May-10-2018, 03:49 PM
Last Post: snippsat
  Running a code through multiple files in a folder Rai 1 2,521 Feb-13-2018, 12:42 PM
Last Post: Larz60+
  [split] running .py files on Windows metulburr 7 5,364 Sep-14-2017, 09:16 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020