Hey so my music stops playing after ~1 minute. The sound file is ~15 minutes long, so it shouldn't be stopping. It also makes other sounds in the program not work. I am also trying to set the player to loop, so if someone knows how to do that please check my code. Any help appreciated!
import pyglet
music = pyglet.media.load('warmusic.wav', streaming= False)
player = pyglet.media.Player()
player.queue(music)
player.volume=.5
player.eos_action='loop'
player.play()
pyglet.app.run()
Related
I am attempting to get my script to open up a game through steam and then start a world. This all works fine up until the part where I need to navigate the game. I'm assuming that the modules that let you control the mouse just move to points rather than actually moving the mouse which the game doesn't pick up. The game only becomes responsive when I myself move the mouse around IRL.
I've tried using pyautogui, mouse, pynput, and a couple of more but have had no luck. The game doesn't respond until I intervene. I'd love any help ya'll could give me. Thanks.
Here's some of my code, if it helps.
import pyautogui
import time
def openWorld():
#pyautogui.moveTo(230, 530, 1)
pyautogui.click(x=230, y=530)
I recently wrote my first pygame program and am working on a second, and discovered an issue with running the program. I use the editor MuEditor for Python 3.8.6, and when I run the game using this editor it works exactly how I want it to. Although, if I run the program from ANY other editor such as IDLE or PyCharm, it ramps up the game speed and displays the fonts incorrectly, making the game much more difficult to play. My friend wants to be able to play the games I write, so I sent him the code through an email and they ran it through MuEditor, and it still worked incorrectly. The game only runs how it should when I run it from my computer in MuEditor, and I was wondering if anyone else has had this problem or if there's a fix for it? I highly doubt the error here is in my code, but I can provide it if necessary.
Use pygame.time.Clock to control the frames per second and thus the game speed. See pygame.time.Clock.tick():
This method should be called once per frame. It will compute how many milliseconds have passed since the previous call.
The method tick() of a pygame.time.Clock object, delays the game in that way, that every iteration of the loop consumes the same period of time.
That means that the loop:
clock = pygame.time.Clock()
run = True
while run:
clock.tick(60)
runs 60 times per second.
I've been working on this for a while but everything I find seems to be a dead end so I could use some help troubleshooting.
import pygame
file = open("C:\\Users\\MyName\\Music\\oggTest.ogg")
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)
This code is supposed to grab an audio file and play it using the mixer from pygame. Very simple, and I've seen other questions here asking about how to do it but mine's still not working for some reason. Right now, I have no errors when I'm running the code. The only problem is that nothing happens. No audio gets played. I have a hunch that it has something to do with my IDE (pycharm), but I don't know for sure if that's the case. Also, the filepath part is a bit confusing to me. I don't see any reason why it wouldn't work but perhaps I'm missing something obvious. Thanks in advance for helping out.
As per the advice of a YT video, I converted the mp3 file I originally had to an ogg file. Not sure if that was necessary, and honestly I'd prefer not to have to do it in the future.
Okay, I found the answer after a bit more research. Taking out the pygame.init() worked. I guess it didn't like doing both pygame.init() and pygame.mixer.init() for some reason.
I wrote this code, where I make 3 buttons and then when I hit 1 button, it plays sound A, I hit button 2, it plays sound B, etc.
from winsound import *
PlaySound("ooooOOooo.wav", SND_ASYNC)
PlaySound("WOOOWoooowooo", SND_ASYNC)
The buttons work and the sounds come out fine, but when I click 1 button and then second button right after that, it stops the first sound and plays the second.
How to make them play at the same time, so that the first still plays while the second one is added to play them togeter. I thought the mistake might be in flags, I tried a few combinations with the "|" operator but the problem still remains :(
Here are the resources:
http://docs.python.org/2/library/winsound.html
I would prefer sticking to the python std library please :)
Thank you!
According to the documentation
You need to do the following when using filenames:
PlaySound("ooooOOooo.wav", SND_ASYNC | SND_FILENAME)
PlaySound("WOOOWoooowooo.wav", SND_ASYNC | SND_FILENAME)
failing to do so is probably causing a None sound call to PlaySound which will cause:
If the sound parameter is None, any currently playing waveform sound is stopped. If the system indicates an error, RuntimeError is raised.
Well, I thought using other modules is bad, but pygame works fine. Sounds are played well and importing this module into the cx_freezer is easy :)
I am currently making a game in Python. I am not using PyGame, just the console (non-GUI)
When you start the game, you will get the logo to the game, and a lot of information about the "journey" you just started. There is a lot of text, so while the text is scrolling, I want to have a song played in the background.
I start the music with the following code:
def new_game():
import winsound
winsound.PlaySound("intro.wav", winsound.SND_ALIAS)
LVL1_INTRO()
The only problem is: it won't continue to LVL1_INTRO() until the music have stopped playing. It's a problem, as the music is approximately 1-2 minutes long.
Is there any way to fix this? After the music have started, it will continue with LVL1_INTRO()
If it is possible, I would be happy if there is a code for stopping the music as well, so I don't need to start cutting the music, and make it exactly the same lenght as the intro.
Thank you very much!
According to the documentation you use the SND_ASYNC flag.
winsound.SND_ASYNC
Return immediately, allowing sounds to play asynchronously.
To stop playing, call PlaySound with a NONE argument.
winsound.PlaySound(None, winsound.SND_ASYNC)
I don't have experience with this module, but it looks as though you can play sounds asynchronously. See http://docs.python.org/2/library/winsound.html and look at SND_ASYNC.