devenh
Posts: 25
Joined: Fri Jun 05, 2015 9:11 pm

pygame.mixer.music.queue not working for me!

Mon Mar 28, 2016 2:49 pm

I'm sure I'm missing something simple, but I just can't get the queue function to work. I'm using Python 3.4.2 under the latest Jessie release on a Pi 3. I have tested with wav and ogg files.

Code: Select all

PATHAUDIO = '/home/pi/Music/'
ext = '.ogg'
print(ext)
pygame.mixer.init()
pygame.mixer.music.load(PATHAUDIO + 'first' + ext)
pygame.mixer.music.play(2)
pygame.mixer.music.queue(PATHAUDIO + 'second' + ext)
#pygame.mixer.music.play()
print('done')
The first audio file gets played three times, but the second one is never played.

User avatar
elParaguayo
Posts: 1896
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: pygame.mixer.music.queue not working for me!

Wed Mar 30, 2016 7:00 pm

Can you verify that the second file plays through pygame?

Also, how are you running this code? If you execute it as a python script then, without some loop at the end, the code will just exit.

I don't have a pi that I can easily test this on. However, I've tested it on my laptop (Ubuntu) and it works as expected for me.

This was the code I ran:

Code: Select all

import pygame
import time

mix = pygame.mixer  # This is just me being lazy!
music = mix.music  # ditto

f1 = "/usr/share/sounds/alsa/Front_Center.wav"
f2 = "/usr/share/sounds/alsa/Front_Left.wav"

mix.init()
music.load(f1)
music.play(2)
music.queue(f2)
print "Done"

time.sleep(15)
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

devenh
Posts: 25
Joined: Fri Jun 05, 2015 9:11 pm

Re: pygame.mixer.music.queue not working for me!

Sat Apr 02, 2016 1:14 pm

elParaguayo wrote:Can you verify that the second file plays through pygame?
Yes it does.
Also, how are you running this code? If you execute it as a python script then, without some loop at the end, the code will just exit.
I thought the same thing and had already tried adding sleep(20), but same result.

It appears the problem is pi specific as the code works on your laptop.

devenh
Posts: 25
Joined: Fri Jun 05, 2015 9:11 pm

Re: pygame.mixer.music.queue not working for me!

Sun May 22, 2016 5:13 pm

If pygame.mixer.music.queue does not work, can anyone suggest an alternative python library that has the ability to queue music in a non blocking fashion?

Nebi
Posts: 2
Joined: Sat Oct 14, 2017 9:39 pm

Re: pygame.mixer.music.queue not working for me!

Sat Oct 14, 2017 10:13 pm

it was dissolved! click here [-----> que.py you can download and edit the file!

this code can help you!

Code: Select all

        import pygame, time
        from tkinter import *

        root = Tk()
        c = ["music1.mp3", "music2.mp3", "music3.mp3"] #you can add more
        x = 0

        def music():
           pygame.init()
           pygame.mixer.init()
           pygame.mixer.music.load(c[x])
           pygame.mixer.music.play(0)
           que()

        def que():
           global x, c
           pos = pygame.mixer.music.get_pos()
   
           if int(pos) == -1:
              x += 1
              pygame.mixer.music.load(c[x])
              pygame.mixer.music.play(0)
      
           root.after(1000, que)
      
      

        music()



        root.mainloop()

Nebi
Posts: 2
Joined: Sat Oct 14, 2017 9:39 pm

Re: pygame.mixer.music.queue not working for me!

Sat Oct 14, 2017 10:30 pm

devenh wrote:
Mon Mar 28, 2016 2:49 pm
I'm sure I'm missing something simple, but I just can't get the queue function to work. I'm using Python 3.4.2 under the latest Jessie release on a Pi 3. I have tested with wav and ogg files.

it was dissolved! click here: que.py you can download and edit the file!

this code can help you!

Code: Select all

    import pygame, time
    from tkinter import *

    root = Tk()
    c = ["music1.mp3", "music2.mp3", "music3.mp3"] #you can add more
    x = 0

    def music():
       pygame.init()
       pygame.mixer.init()
       pygame.mixer.music.load(c[x])
       pygame.mixer.music.play(0)
       que()

    def que():
       global x, c
       pos = pygame.mixer.music.get_pos()
   
       if int(pos) == -1:
          x += 1
          pygame.mixer.music.load(c[x])
          pygame.mixer.music.play(0)
      
       root.after(1000, que)
      
      

    music()



    root.mainloop()

Return to “Python”

Who is online

Users browsing this forum: chrischi and 18 guests