You're not starting the event loop. The way the music player works is
that it uses internal events to do things. So when you
do .queue(song), you're actually triggering an event that'll load the
song as soon as possible. Playing is also via event. If you don't
start the event loop, it'll think you're not done setting things up
yet.

Furthermore, I haven't checked, but I'm almost certain doing
time.sleep(5) will simply pause everything for 5 seconds, not let it
play for 5 seconds, as you'd expect. Because you need to keep
processing the events which actually play the song.

This 'while running == 1' way, isn't going to easily work. I'll
explain the basic format your program is going to have in pseudocode
with python code sprinkled in:

<imports>

<set up socket, show directory listing>

player = pyglet.media.Player()

def update(self,dt):
  if not player.playing:
    #we have just started, or we have reached the end of a song
    song = raw_input()
    player.queue(pyglet.media.load(song))
    player.play()
  else:
    #the player is playing, we can show the time somewhere
    #or whatever. Called about ten times a second, ideally.

#schedule so that update() is called ten times a second.
pyglet.clock.schedule_interval(1/10.0,update)
#start the event loop
pyglet.app.run()


Hope this helps.



On Jul 19, 3:10 am, musicmac <[email protected]> wrote:
> OK
> i now have
> [code]
> import os
> import socket
> import time
> import pyglet
>
> port = 8081
> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>
> print 'ip adress?'
> ip = raw_input();
> dir = os.getcwd()
> print os.listdir(dir)
> player = pyglet.media.Player()
> running = 1
> while (running == 1):
>     print "which song now? (type the file name in full don't forget
> the .mp3)"
>     song = raw_input()
>     player.queue(pyglet.media.load (song))
>     time.sleep(1)
>     player.play()
>     print player.volume
>     print player.time
>     time.sleep(5)
>     print player.time
> [/code]
>
> But player.play just isn't actually doing anything, when i print the
> time at both points it gives me 0.0!?!!?!
>
> On Jul 18, 11:58 pm, musicmac <[email protected]> wrote:
>
>
>
>
>
>
>
> > the reason i'm sending the song name to a socket is so that it can
> > interact with the other machine running the client version, which will
> > just play the song, so its a multi room music player, see?
>
> > and i'll start reading the docu etc etc now
>
> > On Jul 18, 11:28 pm, Michael Red <[email protected]> wrote:
>
> > > Uh, wait. You're sending the song name to a socket, then playing the 
> > > music.
> > > Why send the song name?
>
> > > Brutish solution is this:
>
> > > def update(dt):
> > >   global music
> > >   if not music.playing:
> > >     pyglet.app.exit()
>
> > > and before pyglet.app.run():
>
> > >   pyglet.clock.schedule_interval(1/60.0, update)
>
> > > This should work. For reference, check the documentation on music playback
> > > and event loops. API reference could also help.
>
> > > On 18 July 2011 17:40, musicmac <[email protected]> wrote:
>
> > > > hey guys
> > > > i just started using pyglet this morning for a music project, the idea
> > > > is to be able to play the same song on 2 machines much like a sonos
> > > > box or something but the cheap man way. I currently have
> > > > [code]
> > > > import os
> > > > import socket
> > > > import pyglet
>
> > > > port = 8081
> > > > s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> > > > print 'ip adress?'
> > > > ip = raw_input();
> > > > dir = os.getcwd()
> > > > print os.listdir(dir)
> > > > running = 1
> > > > while (running == 1):
> > > >    print "which song now? (type the file name in full don't forget
> > > > the .mp3)"
> > > >    song = raw_input()
> > > >    s.sendto((song), (ip, port))
> > > >    music = pyglet.resource.media(song)
> > > >    music.play()
> > > >    pyglet.app.run()
> > > > [/code]
> > > > but the program just sticks at playing the song and pyglet won't
> > > > close :(
> > > >  TLDR how can i close pyglet after a song has played?
>
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "pyglet-users" group.
> > > > To post to this group, send email to [email protected].
> > > > To unsubscribe from this group, send email to
> > > > [email protected].
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/pyglet-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to