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()
@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) pre>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') pre>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.
p>
@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()