python - music problems when using pygame + multiprocessing -


i'm tring run script play music via process. code below stripped down version of code it's enough replicate problem. if call normal() procedure hear music know procedure correct , connected properly, however, if call normal() using multiprocessing there no sound... runs normal() still no audio...

any suggestions? thanks!

#!/usr/bin/python #  # import required python libraries import pygame, time import multiprocessing mp localtime = time.asctime( time.localtime(time.time()) ) pygame.init() cs = 0   def normal( cs ): # main loop     try:         if cs == 1:                while cs == 1:                  print " starting normal function"                     pygame.mixer.music.load('/home/user/scripts/music.mp3')                  pygame.mixer.music.play()                  time.sleep(20)                  pygame.mixer.music.stop()                             #return;      except keyboardinterrupt:         print "quit"   try:    print " starting music"      # play here    cs = 1   p2 = mp.process(target=normal, args=(cs,))   p2.start()   p2.terminate()  #normal( cs )             except keyboardinterrupt:   print "  quit"  # end script     

try this:

pygame.mixer.music.load('/home/user/scripts/music.mp3') pygame.mixer.music.play(-1,0) # add args sleep(20) #remove line mixer.music.stop() #remove line 

adding pygame.mixer.music.play(-1,0) means music play in loop until quit game e.g.

try remove sleep(20) , mixer.music.stop().

also check if playing 44.1khz mp3, default 22050 frequency works, 48khz mp3 plays in less half speed - 48000 or 24000 works then.

or try approach depending on sample rate:

pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096) sound = pygame.mixer.sound('/home/user/scripts/music.mp3').play() 

or try this.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -