Songs events in python game - python

I am trying to implement a game in python and i would like to have some effects songs in my game. I have done the following:
MusicStart.play()
MusicStart.stop()
I have assign all the details that needed. I want to play the song only one time. That i have done is repeated until the user press any input button.
Does someone know how to do it?

Not completely clear about your question, but here's what I did to implement music in my game (pygame):
pygame.mixer.music.load(os.path.join('.', 'path-to', 'your-music-file.wav'))
pygame.mixer.music.play(0, 0.0)
That way, the music file plays once only. Note that path-to would be the sub-folder you have the music files in (if you have one: if the file is in the same directory as the code, skip it) and your-music-file.wav would be your file, whether it's an .mp3, .wav, etc.
You can see the documentation page on it here.

Related

I need help.Trying to make a mp3 player which when playing a music detect pitch

So far i already have the Application buttons etc... And i can open the file location of the music players music list which i can select the specific tracks.
I can also play the track and pause/stop the track
At the moment i am trying to use Aubio but its not going so well since i dont know how to use it well. Tutorials on this is scares as well.
Basically my objective is to make a music player which tracks change in pitch - when pitch changes switch the image placed in the tK after 1 sec - (i dont know if this can be done but) image change is changed to a random image in a specific folder
I have tried using different sources to get me to understand but its not working well - i am a slow beginner and need some sort of help to get me to my goal
Sorry forgot to mention - This is all being done in a TK window - i

Movie and Sound component won’t play simultaneously in PsychoPy

I am trying to develop a basic experiment in the PsychoPy Builder where a silent movie plays in the background while I go through a .csv list to play a sequential series of about 100 very short sounds (about 300 milliseconds each). When I play the .csv list by itself, the sounds play perfectly like I would expect, but when I add the video component, only the first sound in the list will play and it won’t play the entire list of sounds. The video does continue to play, but somehow seems to interfere with the sound component or reading through the .csv file.
I tried deactivating the audio of the silent movie because I thought this could interfere with the sound component, but this does not resolve the issue.
It seems the program is waiting for the video to end before it can repeat the loop and go to the next sound in the list, but instead the program just closes as soon as the video ends. Furthermore, I want the single video to be playing while the sound component loops through the list, but I don't know how to apply the loop only to one component and not the video component that is supposed to play simultaneously with the sounds.
I feel like this should be very easy to achieve, yet I could not find someone with a similar issue when googling a solution. Your help is much appreciated.

Is using a singleton the answer?

I'm trying to create a snips app to play songs using Python 3 and the python-vlc library. I am able to play my songs, but unable to stop them. The action will not run again while the song is playing, but other actions will, so I'm looking to put the stop function in a seperate file. The problem with this, is it creates a second instance of vlc and does not stop the current song.
I'm wondering if creating a singleton of the vlc object would allow me to accomplish this.
Does anyone have any recommendations?
In my opinion I think you can use Singleton for playing and pausing/stopping music.
It would make you able to control the only instance of the class that is initiated.
Especially if you only want to play small snippets of each song (kinda like SongPop I guess?), you'll be sure that no more than one instance of the class is initiated, and can be quite sure where and when it is used.

Key repeat in browser from python code

Note : I am pretty surprised I did not see that same question on this forum, if I missed it please link in comment :)
I am writing a bot in python that would eventually be able to play a browser-based video game (HTML5 canvas game, not Flash). In order to do that I need to simulate the keyboard events from the python code.
I thought pyautogui would do the work, but unfortunately it seems the only way to repeat a key is to do pyautogui.press(key) in a loop, and it is not good at all for playing games as the move is not smooth at all.
I found some solutions for Windows, but I need a solution for macOSX.

Why do I have to press the key multiple times to move?

So, I am writing a game in python and pygame. I was wondering, How come I have to press the "w" key multiple times to move up? I want to be able to hold any key and that action would be repeated. Also, Why does my dagger not "swing" when the character is faced down? This site is making me mad, as I am unable to format my code correctly, so just download it please.
This is where to get all the files (including the .py file):
https://www.mediafire.com/folder/k9ai685abradg/DeadWorld_Infestation_2_18-10-39
I know how buggy it is, but I want to work on it over the summer and get some stuff done.
pygame.event.get() only notifies you if a state has changed, e.g. the state of your W-key changed to pressed. I assume that you're looking for pygame.event.get()[K_w] which tells you if a key is in a pressed-state. The details about that command can be found in the pygame docs.

Categories