[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[SPAM] [pygame] How to play one file at a time with pygame
- To: pygame-users@xxxxxxxx
- Subject: [SPAM] [pygame] How to play one file at a time with pygame
- From: toufik <belaalatoufik@xxxxxxxxx>
- Date: Fri, 19 May 2017 08:58:06 +0100
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Fri, 19 May 2017 03:58:20 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version; bh=Bz+q/jTSy8jMBu9JJZeDTEJlNBovt2ODldP/bME1Aw0=; b=ggfAmdBsmqRXeM8o2hKbx5hRI7JbOESNHqQGhK2ptjYiVueW3rVeSn/UJ3C1PR26Jh xp+LC6xQO9fsP11+ditB3T9EJ3vHkDDOXsaEbuSx8I/uXX5rwXIMmFM3zfmfUw1uCkTQ XwhsNj7mperR/FYQLxT3Z1YM2HwozbjILJIzfBqqudVtPv7mOCecivc14paD8QsKyIYG zrqQoZ3AoPg/Py2ZbzTwjejrcpDP4cvII68u1m5xVK/6Mnhan2q9DnDsR7yJwaFwZv7q eaoCUac2P8M1EcEl3qgpZGpw2FwB98PhKPr7YQGdyuEcGqFC3gAreCHpRlLtDJlLDoPj 6QmA==
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0
Hello.
My question is how can I play one file at a time with pygame.I used
the for loop and it didn't work.
Any help please.
# -*- coding: utf-8 -*-
import wx
import os
import time
import pygame
from pygame.locals import *
started = False
playing = True
old_track = ''
pygame.mixer.pre_init(44100,-16, 2, 1024 * 3 )
pygame.init()
pygame.mixer.music.load('7.mp3')
def holder():
time.sleep(0.001)
def play(track):
global old_track, playing, started
MUSICENDEVENT = USEREVENT
t = wx.PyTimer(holder)
if track == old_track:
pygame.mixer.music.set_endevent(MUSICENDEVENT)
for event in pygame.event.get():
if event.type == MUSICENDEVENT :
pygame.mixer.music.load(track)
started = False
playing = True
if not started:
#print 1
pygame.mixer.music.play()
playing = True
started = True
elif playing:
pygame.mixer.music.pause()
playing = False
else:
pygame.mixer.music.unpause()
playing = True
else:
pygame.mixer.music.load(track)
pygame.mixer.music.play()
started = True
playing = True
old_track = track
t.Start(10)
def rewind():
pygame.mixer.music.rewind()
class Test(wx.Frame):
def __init__(self, parent, id, title):
super(Test, self).__init__(parent, id, title)
global track
track = ''
p = wx.Panel(self,-1)
mainSizer = wx.BoxSizer(wx.VERTICAL)
buttonsSizer = wx.BoxSizer(wx.HORIZONTAL)
self.b1 = wx.Button(p,-1,u'ok')
self.b1.Bind(wx.EVT_BUTTON, self.OnOk)
self.b2 = wx.Button(p, -1, u'rewind')
self.b2.Bind(wx.EVT_BUTTON, self.onRewind)
buttonsSizer.Add(self.b1, 0, wx.ALL, 3)
buttonsSizer.Add(self.b2, 0, wx.ALL, 3)
mainSizer.Add(buttonsSizer, 0, wx.ALL|wx.EXPAND, 5)
p.SetSizer(mainSizer)
self.Show(True)
def OnOk(self,evt):
t = wx.PyTimer(holder)
files = ['1.mp3', '2.mp3', '1.mp3']
for i in files :
play(i)
#while pygame.mixer.music.get_busy():
#time.sleep(0.05)
#t.Start(10)
def onRewind(self, event):
rewind()
app = wx.App()
Test(None,-1,'frame')
app.MainLoop()