[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] cd - SOLUTION
Finally I found solution, using threading. I had a hard time with
cdx.init() - MUST be inside the function - and cdx.get_busy() that
simply in thread does not work. So I used a length of just playing track
to check the end of song.
Hoping it helps someone, too
import pygame, threading
from pygame.locals import *
def playTracks(tracks):
cdx.init()
for track in tracks:
print "Playing track: ", track
cdx.play(track)
while 1:
pygame.time.wait(1000)
elapsedTime = int(cdx.get_current()[1])
# at the song's end there is 0 here
# cdx.get_busy simply doesnt work with me here
if not elapsedTime:
break
elif not (elapsedTime % 60):
print "Still playing ....", elapsedTime, "seconds."
print "End track ... ", int(cdx.get_track_length(track)),
"seconds.", "\n"*2
cdx.quit()
print "Total end."
pygame.init()
cdx=pygame.cdrom.CD(0)
tracksToPlay=(11,1,4,0)
x=threading.Thread(target=playTracks, args=(tracksToPlay,))
x.start()
print "Reaching this immediately.\n"
# pygame.quit()
-----------------------------------------------------------------
Pavel
andrew baker napsal(a):
Howzabout
tracks = [2,5,7]
track_index = 0
if CD.get_busy() = False:
CD.play(tracks[track_index])
if track_index < len(tracks):
track_index += 1
else:
track_index = 0
On Thu, 24 Feb 2005 08:45:38 +0100, gen2n <gen2n@xxxxxxxxx> wrote:
I thing this would stop the script.
Is it possible to play it on a background, as the simple CD.play(1) would
do?
gen2n ICQ 176015287
Bob the Hamster napsal(a):
On Wed, Feb 23, 2005 at 03:31:12PM +0100, gen2n wrote:
I tried to play some tracks from my CD using: for track in 2,5,7:
CD.play(track) It doesnt work. It plays only the last one (7), all the
previous are always interrupted but the next track. Could it be somehow
solved inside pygame without need of threading modul? Pavel CD.play starts
the track playing and then returns instantly. It does not wait for the track
to finish. You probably want something like this: for track in 2,5,7:
CD.play(track) while CD.get_busy(): time.wait(1000) Hope that helps! --- Bob
the Hamster