Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Playing sound
-
I’m trying to play some music in the back ground of a game I’m making using scene. I’m not sure why it’s not playing?
class MyScene (Scene): def setup(self): sound.set_volume(1) bg_music = sound.Player('3 card monte beat (90.00BPM) - MAIN OUT.wav') bg_music.number_of_loops = -1 bg_music.play()
-
Anybody out there. I remember on one of my first post someone said that we can get answers quick on here. I know it’s a real simple problem way above everybody else is pay grade but I haven’t been able to figure it out. I would also like to politely mention that my last post didn’t get much going and I have seen more and more read the docs as the comments or read this other post. Again I read docs but at times have trouble understanding them
-
@resserone13 I don't know why but if you put your four lines outside the scene setup but just after the run scene, it works. Good luck
-
@cvp do you mind showing me an example. I’ve moved the four line to every where I can think of and can’t get it to work.
-
@resserone13 this works for me, from Pythonista examples
from scene import * import sound class NoiseScene (Scene): def setup(self): self.sprite = SpriteNode('card:BackGreen5', size=self.size, position=self.size/2, parent=self) self.offset = Vector2(0, 0) self.touch_start = Point(0, 0) #sound.set_volume(1) #bg_music = sound.Player('mypiano.mp3') #bg_music.number_of_loops = -1 #bg_music.play() def did_change_size(self): self.sprite.position = self.size/2 self.sprite.size = self.size def touch_began(self, touch): self.touch_start = touch.location def touch_moved(self, touch): offset = self.offset + (self.touch_start - touch.location) self.sprite.shader.set_uniform('u_offset', offset) def touch_ended(self, touch): self.offset += (self.touch_start - touch.location) run(NoiseScene(), multi_touch=False) bg_music = sound.Player('mypiano.mp3') bg_music.number_of_loops = -1 bg_music.play()
-
@resserone13 are you sure that the .mov file is in the same folder as your script?
-
@cvp yes. It is in the same folder as the script. I also don’t get any errors say file can’t be found.
I copied and paste your code into Pythonista on my iPhone 11 and I don’t hear any sound. I wonder why?
-
@resserone13 if you create a little script with only the sound lines, without scene, does it work?
-
@resserone13 said:
I copied and paste your code into Pythonista
I guess you did remark that I changed the sound file because I don't have yours.
-
@cvp I changed the sound to a stock sound and I works. Ima gonna pull up a small script and see if I can just get the sound to play. Thanks for your advice.
-
@cvp ive got it working with a stock sound but not my wav file. It must be something with my wav
-
@resserone13 perhaps also but with one mp3, it did not work in the scene setup and did work outside the scene, thus it seems there is a problem.
-
@cvp I got it to work. I’m nice you told me where to put it I had the file name incorrect by one space. Now the problem is that the bg music is cut off by some of the sound effects. When you choose the wrong card it makes a buzzer sound and that sound cuts off the bg music?
-
@resserone13 sorry but I can't help more, I don't know anything in sound nor scene 🤫
-
@cvp ok. Thanks for your help. I appreciate it.
-
@cvp I was able to fix the background music from stopping and being interrupted. I had to remove the volume in pitch settings I had on the two sound effects that were causing the trouble. I’m guessing the sound effects were interrupting the volume in pitch and canceling out the background music.
-
@cvp I’ve got it to work with all the other sound effects by using the sound.playeffect(). I think there might be a problem when you use sound.player() with sound.playeffect(). This is what I’m using.
class MainScene (Scene): def setup(self): bg_music = sound.play_effect('3 card monte beat (90.00 BPM) - MAIN OUT.wav', volume=.25) bg_music.looping = True