How do you loop music in Pygame Subset for Android?

I have been trying to loop music in an Android game written with PyGame Subset. This is what I have so far, it only plays the audio file once. I really want to use the built-in loop function , So that I don’t have to use a timer to manually loop the audio. Any ideas?

import pygame
try:
import pygame.mixer as mixer
except ImportError:
import android_mixer as mixer
if mixer:
mixer.music.load("woo.mp3")
mixer.music.play(-1)
while True:
if mixer:
mixer.periodic()

Note that it does not work in Android 5.x. I know this is an old post, but I also encountered this problem. Due to a bug in the mixer module, zenopython’s answer will apply to some adjustments. If you look at the anroid.mixer module and look at the music course you will see.

@staticmethod 
def get_busy():
return music_channel.get_volume()

You can see this Get_volume() is actually called, and it always returns 1.0. To solve this problem, I copied the mixer.py file into my game directory and changed it to

@staticmethod
def get_busy():
return music_channel.get_busy()

Then imoport mixer, it works. So like

import pygame
try:
import pygame.mixer as mixer
except ImportError:
import mixer
if mixer:
mixer.music. load("woo.mp3")
mixer.music.p lay(-1)
while True:
if mixer:
if mixer.music.get_busy() == False:
mixer.music.play(-1)

This worked for me.

As mentioned above, this does not work in 5.x.

Another solution is to simply arrange the effective music< /p>

mixer.music.load('music')
mixer.music.play()
mixer.music.queue('music')

Usually, there are many errors in the mixer.music module in pgs4a. Another error I found is in mixer.music.pause() and mixer.music.unpause(). unpause() just calls pause again (), so I also have to edit it to allow the music to be paused when the game is stopped. See below

if android: 
if android.check_pause():
mixer.music.pause()
android.wait_for_resume()
mixer.music.unpause()

I have been trying to use PyGame Play music in a loop in an Android game written by Subset. This is what I have so far, it only plays the audio file once. I really want to use the built-in loop function so that I don't have to use a timer to loop the audio manually. Any ideas?

import pygame
try:
import pygame.mixer as mixer
except ImportError:
import android_mixer as mixer
if mixer:
mixer.music.load("woo.mp3")
mixer.music.play(-1)
while True:
if mixer:
mixer.periodic()

Note that it does not work in Android 5.x. I know this is an old post, but I also encountered Here comes the question. Due to a bug in the mixer module, zenopython's answer will apply some adjustments. If you look at the anroid.mixer module and check the music lessons you will see.

@staticmethod 
def get_busy():
return music_channel.get_volume()

You can see that this actually calls get_volume() and it always returns 1.0. To solve this problem, I copied the mixer.py file into my game directory and changed it to

@staticmethod
def get_busy():
return music_channel.get_busy()

Then imoport mixer, it works. So like

import pygame
try:
import pygame.mixer as mixer
except ImportError:
import mixer
if mixer:
mixer.music.load("woo.mp3")
mixer.music.play(-1)
while True:
if mixer:
if m ixer.music.get_busy() == False:
mixer.music.play(-1)

This works for me.

As mentioned above, this is in 5. .x does not work.

Another solution is to simply arrange the effective music

mixer.music.load('music')< br />mixer.music.play()
mixer.music.queue('music')

Usually, there are many errors in the mixer.music module in pgs4a. Another error I found It is in mixer.music.pause() and mixer.music.unpause(). unpause() just calls pause() again, so I also have to edit it to allow the music to be paused when the game is stopped. See below

if android: 
if android.check_pause():
mixer.music.pause()
android.wait_for_resume()
mixer. music.unpause()

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1743 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.