Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
app-pyaudioplayer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
santiago duque
app-pyaudioplayer
Commits
0e4dba85
Commit
0e4dba85
authored
Jan 13, 2025
by
santiago duque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
now working with pygame keyboard
parent
b0e4be43
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
27 deletions
+37
-27
main.py
main.py
+37
-27
01_cobra.mp3
sounds/01_cobra.mp3
+0
-0
02_elefant.mp3
sounds/02_elefant.mp3
+0
-0
03_croc.mp3
sounds/03_croc.mp3
+0
-0
04_wolf.mp3
sounds/04_wolf.mp3
+0
-0
No files found.
main.py
View file @
0e4dba85
import
os
from
os.path
import
isfile
,
join
import
pygame
import
time
import
signal
import
keyboard
from
storage_media
import
USBDeviceHandler
# from storage_media import USBDeviceHandler
# import time
# import signal
# import keyboard
pygame
.
init
()
# window = pygame.display.set_mode((300,300))
clock
=
pygame
.
time
.
Clock
()
dir_path
=
os
.
getcwd
()
sound_dir
=
os
.
getcwd
()
+
"/sounds"
...
...
@@ -14,7 +20,9 @@ cut_current_sound = False
channel
=
False
current_sound_index
=
-
1
usb_handler
=
USBDeviceHandler
()
contentlist
=
sorted
(
contentlist
)
# usb_handler = USBDeviceHandler()
def
setup_sounds
():
for
content
in
contentlist
:
...
...
@@ -22,13 +30,14 @@ def setup_sounds():
if
content
.
endswith
(
".mp3"
)
or
content
.
endswith
(
".wav"
):
sound
=
pygame
.
mixer
.
Sound
(
join
(
sound_dir
,
content
))
sound_array
.
append
(
sound
)
print
(
content
)
print
(
sound_array
)
def
play_sound
(
index
):
global
cut_current_sound
global
current_sound_index
global
channel
global
channel
if
not
cut_current_sound
:
current_sound_index
=
index
...
...
@@ -36,48 +45,49 @@ def play_sound(index):
while
channel
.
get_busy
():
pygame
.
time
.
wait
(
100
)
# ms
print
(
"Playing..."
)
pygame
.
event
.
clear
()
print
(
"Finished."
)
""" todo
make sounds stop when new key pressed
else:
if current_sound_index == index:
current_sound_index = index
channel = sound_array[current_sound_index].play()
while channel.get_busy():
pygame.time.wait(100) # ms
print("Playing...")
print("Playing...
pygame.init()
")
print("Finished.")
else:
print("STOP.")
"""
pygame
.
init
()
setup_sounds
()
run
=
True
while
run
:
clock
.
tick
(
30
)
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
QUIT
:
run
=
False
while
True
:
try
:
# used try so that if user pressed other than the given key error will not be shown
if
keyboard
.
is_pressed
(
"q"
):
print
(
"You Pressed A Key!"
)
play_sound
(
0
)
elif
keyboard
.
is_pressed
(
"w"
):
print
(
"You Pressed A Key!"
)
play_sound
(
1
)
elif
keyboard
.
is_pressed
(
"e"
):
print
(
"You Pressed A Key!"
)
play_sound
(
2
)
elif
keyboard
.
is_pressed
(
"r"
):
print
(
"You Pressed A Key!"
)
play_sound
(
3
)
except
:
break
# if user pressed a key other than the given key the loop will break
if
event
.
type
==
pygame
.
KEYDOWN
:
print
(
"you pressed "
+
pygame
.
key
.
name
(
event
.
key
))
if
event
.
key
==
pygame
.
K_q
:
play_sound
(
0
)
elif
event
.
key
==
pygame
.
K_w
:
play_sound
(
1
)
elif
event
.
key
==
pygame
.
K_e
:
play_sound
(
2
)
elif
event
.
key
==
pygame
.
K_r
:
play_sound
(
3
)
pygame
.
quit
()
exit
()
# time.sleep(5.5)
# signal.pause()
sounds/cobra.mp3
→
sounds/
01_
cobra.mp3
View file @
0e4dba85
File moved
sounds/elefant.mp3
→
sounds/
02_
elefant.mp3
View file @
0e4dba85
File moved
sounds/
leopard
.mp3
→
sounds/
03_croc
.mp3
View file @
0e4dba85
File moved
sounds/wolf.mp3
→
sounds/
04_
wolf.mp3
View file @
0e4dba85
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment