-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mp3 music #247
Comments
sound services associated with scenes:
The cost effective way for you would be to go with one of those approaches. Additional info: |
Hi Claudio, Thanks for pointing me in the right direction. I tried the SDL (pygame) part, and here is what I found out. I tried this code #!/usr/bin/python3
#-*- encoding: utf-8 -*-
import cocos
from cocos.director import director
from cocos.audio.pygame import mixer, music
director.init()
intro = cocos.scene.Scene()
mixer.init()
music.load('music.mp3')
music.play()
music.set_volume(1)
director.run(intro) which throws this exception
I realized that I'm using Python 3, and strings are unicode objects. So I tried to encode my string like this: music.load('music.mp3'.encode()) and I don't have a Traceback anymore. But I can see that the window is frozen (with a white background). Also I hear the typical sound made by Windows when there is an error, though I don't see any error message. I tried the same code in Python 2, and I can hear the music. It seems that the audio might have some problems under Python 3. I'm trying to figure out what it is, but any help (guidance) would be appreciated. Daniel. |
If this is of any help, when doing |
Excuse the conciseness, I'm in a hurry Summary
Background about SDL support:
At this point in time, there are probably bugs coming from
I was never deeply familiarized with the SDL code, my 2to3 conversion skills are a bit rusty and this weeks I'm hard pressed for time. So, here you are. |
Your conciseness is not so concise. ;) After a morning of debugging I found my problem. The short answer is that smpeg.dll could not be found. Copying it in the same directory as my script solves the problem. The long answer: cocos loads SDL.dll by looking where the module pygame lives, and changes temporarily the current working directory to this path. It loads the dll and changes the current working directory back to where it was. But later on, SDL.dll need smpeg.dll in order to load mp3 files. And the pygame folder is not on the system path. My python 2 worked because the dlls were all in C:\Python27\DLL and this folder is in my system path. I guess the best course of action would be not to change temporarily the current working directory, but to temporarily add the pygame folder to the system path. I still need to pass a bytes object as the filename parameter to the Final observation when trying to use the untested Scene.load_music method, python 3 will throw a ImportError exception in try:
from cocos.audio.pygame import music
_have_music = True
except ImportError:
_have_music = False due to circular dependency which unfortunately is silently caught. The offending line in cocos.audio.pygame.music.py is on line 20 I'm not experimented enough to know the correct way to fix all this. I can try to give it a shot. But your ideas / suggestions would be very much appreciated. Of course, only when you have some more time. Nothing urgent here! Dan. |
Some workaround to reproduce mp3 files using cocos? |
Personally I ended up creating these functions in a from pygame import mixer
from pygame.mixer import music
import pyglet
import cocos
mixer.pre_init(44100, -16, 2, 1024)
mixer.init()
# Make sure we exit the mixer when the application quits
cocos.director.event_loop.push_handlers(on_exit=mixer.quit)
def play(soundtrack):
# music.load(bytes(os.path.join("assets", "music", soundtrack), 'utf-8'))
music.load(pyglet.resource.file(soundtrack))
music.set_volume(0.5)
music.play(loops=-1)
def transition(soundtrack, time):
music.fadeout(time * 1000)
pyglet.clock.schedule_once(next_music, time, soundtrack)
def next_music(dt, soundtrack):
play(soundtrack) Of course pygame should be installed and make sure you have also smpeg installed. I found out that for some unknown reasons, sometimes mp3 files had a delay to start playing, like 3-5 seconds. I reverted back to .ogg files. I hope it helps. Daniel. |
If you dont want to use pygame on your cocos application then maybe pyrilla is worth checking. It is simple and lightweight audio mixer that has no extrernal dependencies. It has no mp3 support but it can easily play ogg and wave audio. |
Hello,
I'm trying to play some music with cocos2d. I'm a bit lost as why my music is not played. Here is a minimal code using pyglet which works:
And here is my attempt in cocos2d which does not work (the windows open correctly but no music is played):
Trying to trace the problem, I found that when the scene enters, cocos is calling cocos.audio.music.control.load(self.music)which actually calls the DummyMusicControl implementation in cocos\audio\music.py.
I want to use AVBin and it's installed on my machine. What am I doing wrong?
I tried to use pygame instead, passing audio_backend='sdl' to director.init(). But this gives this exception:
Daniel.
The text was updated successfully, but these errors were encountered: