Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson04_diy
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4806eb25
authored
Jun 21, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
b2548c51
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
5 deletions
my_music.py
test.wav
my_music.py
View file @
4806eb25
import
pygame
import
pygame
from
pygame
import
locals
from
pygame
import
locals
import
os
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
# 创建窗口
# 创建窗口
...
@@ -11,16 +12,47 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮
...
@@ -11,16 +12,47 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮
last_img
=
pygame
.
image
.
load
(
'last.png'
)
# 上一曲按钮
last_img
=
pygame
.
image
.
load
(
'last.png'
)
# 上一曲按钮
next_img
=
pygame
.
image
.
load
(
'next.png'
)
# 下一曲按钮
next_img
=
pygame
.
image
.
load
(
'next.png'
)
# 下一曲按钮
logo_img
=
pygame
.
image
.
load
(
'logo.png'
)
# 下一曲按钮
logo_img
=
pygame
.
image
.
load
(
'logo.png'
)
# 下一曲按钮
pygame
.
mixer
.
music
.
load
(
'歌曲3.wav'
)
#导入音乐
volume
=
0.5
#控制音量大小的变量
volume
=
1
#控制音量大小的变量
pygame
.
mixer
.
music
.
set_volume
(
volume
)
#设置音量大小
pygame
.
mixer
.
music
.
set_volume
(
volume
)
#设置音量大小
click
=
0
#统计按下鼠标次数
click
=
0
#统计按下鼠标次数
button
=
stop_img
#按钮形状
button
=
stop_img
#按钮形状
#music_list = ['米津玄師&daoko-打上花火.MP3','Alan Walker&Coldplay-Hymn For The Weekend[Remix].MP3','OMFG-I Love You.MP3']
M_list
=
[]
path
=
r'c:/Users/zw/Documents/pygame_lesson04_diy'
filelist
=
os
.
listdir
(
path
)
for
i
in
filelist
:
if
i
[
-
4
:]
==
'.MP3'
or
i
[
-
4
:]
==
'.ogg'
or
i
[
-
4
:]
==
'.wav'
:
M_list
.
append
(
i
)
num
=
-
1
while
True
:
while
True
:
pygame
.
mixer
.
music
.
set_volume
(
volume
)
#设置音量大小
pygame
.
mixer
.
music
.
set_volume
(
volume
)
#设置音量大小
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
x
,
y
=
event
.
pos
#获取坐标
if
x
>
270
and
x
<
370
and
y
>
350
and
y
<
450
:
click
+=
1
if
x
>
120
and
x
<
220
and
y
>
350
and
y
<
400
:
num
-=
1
if
num
<
0
:
num
>
len
(
M_list
)
-
1
pygame
.
mixer
.
music
.
load
(
path
+
'
\\
'
+
M_list
[
num
])
pygame
.
mixer
.
music
.
play
()
play_button
=
stop_img
click
=
0
if
x
>
420
and
x
<
520
and
y
>
350
and
y
<
400
:
num
+=
1
if
num
>
len
(
M_list
)
-
1
:
num
=
0
pygame
.
mixer
.
music
.
load
(
path
+
'
\\
'
+
M_list
[
num
])
pygame
.
mixer
.
music
.
play
()
play_button
=
stop_img
click
=
0
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
#退出程序
exit
()
#退出程序
...
@@ -33,15 +65,20 @@ while True:
...
@@ -33,15 +65,20 @@ while True:
volume
-=
0.1
volume
-=
0.1
if
volume
<
0
:
if
volume
<
0
:
volume
=
0
volume
=
0
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
click
+=
1
if
click
%
2
==
0
:
if
click
%
2
==
0
:
button
=
stop_img
button
=
stop_img
pygame
.
mixer
.
music
.
unpause
()
pygame
.
mixer
.
music
.
unpause
()
else
:
if
click
%
2
==
1
:
button
=
play_img
button
=
play_img
pygame
.
mixer
.
music
.
pause
()
pygame
.
mixer
.
music
.
pause
()
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
#判断音乐是否播放
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
#判断音乐是否播放
num
+=
1
if
num
>
len
(
M_list
)
-
1
:
num
=
0
pygame
.
mixer
.
music
.
load
(
path
+
'
\\
'
+
M_list
[
num
])
pygame
.
mixer
.
music
.
play
()
#播放音乐
pygame
.
mixer
.
music
.
play
()
#播放音乐
# 绘制画面
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
...
...
test.wav
deleted
100644 → 0
View file @
b2548c51
File deleted
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