error:
Traceback (most recent call last):
File "src\\gevent\\greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
File "eel\__init__.py", line 259, in _process_message
File "main.py", line 40, in play_music
pygame.error: Failed loading libmpg123-0.dll: The specified module could not be found.
2020-08-28T18:46:27Z <Greenlet at 0x4b29138: _process_message({'call': 1.305899873486772, 'name': 'play_music', , <geventwebsocket.websocket.WebSocket object at 0x0)> failed with error
pyinstaller command:
python -m eel main.py web --console --onefile --icon=ico.ico
mp3 files don't play but wav files works...
Try the following snippet:
import pygame
mp3_file = 'song.mp3'
pygame.init()
pygame.mixer.init()
clock = pygame.time.Clock()
pygame.mixer.music.load(mp3_file)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
clock.tick(10)
This should play the music and run the rest of the game.
You are able to do the following as well:
import pygame
mp3_file = 'song.mp3'
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(mp3_file)
pygame.mixer.music.play()
pygame.event.wait()
But the game will stop executing and wait for the mp3 to finish. This is because of pygame.event.wait()
There are many examples here: Play MP3 in pygame
Related
Heres the code I'm running:
from playsound import playsound
import threading
threading.Thread(target=playsound, args=('Assets\Loss.mp3',)).start()
When I run this it gives me this error
Error 259 for command:
play "Assets\Loss.mp3" wait
The driver cannot recognize the specified command parameter.
Error 305 for command:
close "Assets\Loss.mp3"
Cannot specify extra characters after a string enclosed in quotation marks.
Failed to close the file: "Assets\Loss.mp3"
Traceback (most recent call last):
File "C:\Users\ekila\Downloads\Smart Auto Bet\Test.py", line 10, in <module>
playsound('Assets\Loss.mp3')
File "C:\Python310\lib\site-packages\playsound.py", line 73, in _playsoundWin
winCommand(u'play {}{}'.format(sound, ' wait' if block else ''))
File "C:\Python310\lib\site-packages\playsound.py", line 64, in winCommand
raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
Error 259 for command:
play "Assets\Loss.mp3" wait
The driver cannot recognize the specified command parameter.
What's a little bit more interested is that when I move the mp3 to the same folder and run
from playsound import playsound
import threading
threading.Thread(target=playsound, args=('Loss.mp3',)).start()
It plays perfectly fine with no errors but I want to have the mp3 stored in the subdirectory
I have playsound version 1.2.2 installed.
I've tried running it without threading
I code in PyCharm and went into C:\Users\MyUser\PyCharmProjects\MyFile and from there went into cmd in that directory, executed pyinstaller --onefile -w main.py. This worked perfect. I grabbed my main.exe from dist and put it into MyFile and executed it but upon doing so it brought up the following error:
Traceback (most recent call last):
File "main.py", line 2, in <module>
from pynput.mouse import Controller, Button
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\keyboard\__init__.py, line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[4752] Failed to execute script main
The purpose of my code is to move around your mouse rapidly until you hold down a, b, and c. Just a fun practical joke. Here is a copy of it:
import keyboard
from pynput.mouse import Controller, Button
import random
import tkinter as tk
root = tk.Tk()
mouse = Controller()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
while True:
xVar = random.randint(0, screen_width)
yVar = random.randint(0, screen_height)
mouse.position = (xVar, yVar)
if keyboard.is_pressed("a") and keyboard.is_pressed("b") and keyboard.is_pressed("c"):
break
I've honestly tried everything. I can't figure out what is going wrong with it. Any help would be appreciated. Thanks!
You have to add --hidden-import="pynput.keyboard._win32" --hidden-import "pynput.mouse._win32", so pyinstaller can include the backend that pynput uses. So something like:
pyinstaller --hidden-import="pynput.keyboard._win32" --hidden-import="pynput.mouse._win32" app.py
You can also add this to your spec file.
hiddenimports=["pynput.keyboard._win32", "pynput.mouse._win32"]
If you are using macOS then replace '_win32' with '_darwin' and if linux, replace with '_xorg'.
The other method is to fallback to a previous version which is not recommended, but just incase you want it. First pip uninstall pynput then:
pip install pynput==1.6.8
music player programming. ran into a problem. The program should play the file that I run using my program. For this, I formatted the code in exe. When I started using my exe an error occurred
Traceback (most recent call last):
File "MP3.py", line 13, in <module>
File "MP3.py", line 7, in music
pygame.error
[1980] Failed to execute script MP3
MP3.py -my python code/
import pygame
import sys
f = str(sys.argv[1])
print(f)
def music(f):
pygame.init()
clock = pygame.time.Clock()
pygame.mixer.music.load(f)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pygame.mixer.init(22050,-16,2)
music(f)
various methods do not help.
although the code with music playback works shortly and in exe as well as the output of the file that I launch by the program
this error
C:\Users\Acer\Documents\Projects\MP3\Test.mp3
Traceback (most recent call last):
File "MP3.py", line 15, in <module>
music(f)
File "MP3.py", line 9, in music
pygame.mixer.music.load(f)
pygame.error
[17280] Failed to execute script MP3
You should first use pygame.mixer.init before using mixer to do anything you want. You can refer to this document for details about how to tweak the parameters of the mixer.
I wanted to use a library in python called pygame-menu in raspberry pi because I wanted to develop a game with somebody else. I tested one of their demos and I got the following error:
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "/home/pi/Pandemic/GameDev.py", line 2, in <module>
import pygame_menu
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/__init__.py", line 66, in <module>
import pygame_menu.themes
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/themes.py", line 386, in <module>
THEME_DEFAULT = Theme()
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/themes.py", line 198, in __init__
bool, pygame.vernum.major == 2) # type: bool
AttributeError: 'tuple' object has no attribute 'major'
Here is also my code:
import pygame
import pygame_menu
pygame.init()
surface = pygame.display.set_mode((600, 400))
def set_difficulty(value, difficulty):
# Do the job here !
pass
def start_the_game():
# Do the job here !
pass
menu = pygame_menu.Menu(300, 400, 'Welcome',
theme=pygame_menu.themes.THEME_SOLARIZED)
menu.add_text_input('Name :', default='John Doe')
menu.add_selector('Difficulty :', [('Hard', 1), ('Easy', 2)], onchange=set_difficulty)
menu.add_button('Play', start_the_game)
menu.add_button('Quit', pygame_menu.events.EXIT)
menu.mainloop(surface)
Can you please help me fix it I ran the program with Thonny
it seems that the error comes from the pygame_menu library. You should check the compatibility between pygame_menu and pygame version. The last version of pygame-menu require pygame 1.9.6 or more.
I have fixed it. It turns out the raspberry pi has a default version of 1.9.4 of pygame and pygame-menu required 1.9.6 and above so I upgraded it with this command:
python3 -m pip install -U pygame --user
There is a link to an mp3 file that needs to be streamed from a URL like http://example.com/music_radio.mp3 and played on a computer. On the Internet, although there are examples of streaming audio, but they are mainly for Python2, and for Python3 there are no such libraries anymore, I tried to do it this way:
import vlc
p = vlc.MediaPlayer ("http://example.com/music_radio.mp3")
p.play ()
But it constantly displays an error:
Traceback (most recent call last): File "PythonProjects / URL /
main.py", line 2, in import vlc File "PythonProjects / URL / venv /
lib / python3.6 / site-packages / vlc / init.py", line 3, in public
import ModuleNotFoundError: No module named 'public'
And the problem is that the public module is not installed. How can you solve this problem or how else can you receive and play audio by reference?
UPD: That link suggests either non-working code, or code using Python2, not Python3
UPD2: When using python-vlc, this error occurs:
Traceback (most recent call last): File
"PythonProjects/URL/main.py", line 4, in
import vlc File "PythonProjects/URL/venv/lib/python3.6/site-packages/vlc.py",
line 203, in
dll, plugin_path = find_lib() File "PythonProjects/URL/venv/lib/python3.6/site-packages/vlc.py",
line 194, in find_lib
ctypes.CDLL('libvlccore.dylib') File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ctypes/init.py",
line 348, in init
self._handle = _dlopen(self._name, mode) OSError: dlopen(libvlccore.dylib, 6): image not found
If this can help
from IPython.display import Audio
Audio(url="http://www.nch.com.au/acm/8k16bitpcm.wav")