Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson6_diy4
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
aa21a66f
authored
4 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
72a2493c
c97682l1384p256a14207/wx978328
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
22 deletions
my_music.py
my_music.py
View file @
aa21a66f
...
@@ -14,13 +14,13 @@ next_img = pygame.image.load('next.png') # 下一曲按钮
...
@@ -14,13 +14,13 @@ next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img
=
pygame
.
image
.
load
(
'logo.png'
)
# 下一曲按钮
logo_img
=
pygame
.
image
.
load
(
'logo.png'
)
# 下一曲按钮
FPS
=
pygame
.
time
.
Clock
()
FPS
=
pygame
.
time
.
Clock
()
music_list
=
[]
music_list
=
[]
path
=
"C:
\\
Users
\\
50639
\\
Desktop
\\
test"
path
=
"C:
\\
Users
\\
50639
\\
Desktop
\\
test"
#路径
filelist
=
os
.
listdir
(
path
)
filelist
=
os
.
listdir
(
path
)
#文件夹内容导入
num
=
-
1
num
=
-
1
a
=
0
a
=
0
for
i
in
filelist
:
for
i
in
filelist
:
if
i
[
-
4
:]
==
".wav"
or
i
[
-
4
:]
==
".ogg"
:
if
i
[
-
4
:]
==
".wav"
or
i
[
-
4
:]
==
".ogg"
:
#筛选所需文件
music_list
.
append
(
i
)
music_list
.
append
(
i
)
#追加
volume
=
0.2
volume
=
0.2
pygame
.
mixer
.
music
.
set_volume
(
volume
)
# 初始播放音量
pygame
.
mixer
.
music
.
set_volume
(
volume
)
# 初始播放音量
click
=
0
click
=
0
...
@@ -35,14 +35,13 @@ while True:
...
@@ -35,14 +35,13 @@ while True:
if
event
.
key
==
locals
.
K_w
:
if
event
.
key
==
locals
.
K_w
:
volume
+=
0.1
volume
+=
0.1
if
volume
>
1
:
if
volume
>
1
:
volume
=
1
volume
=
1
#增强音量
pygame
.
mixer
.
music
.
set_volume
(
volume
)
pygame
.
mixer
.
music
.
set_volume
(
volume
)
#导入音量
if
event
.
key
==
locals
.
K_s
:
if
event
.
key
==
locals
.
K_s
:
volume
-=
0.1
volume
-=
0.1
if
volume
<
0
:
if
volume
<
0
:
volume
=
0
volume
=
0
#减弱音量
pygame
.
mixer
.
music
.
set_volume
(
volume
)
pygame
.
mixer
.
music
.
set_volume
(
volume
)
#导入音量
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
if
event
.
button
==
1
:
# 左击
if
event
.
button
==
1
:
# 左击
x
,
y
=
event
.
pos
x
,
y
=
event
.
pos
...
@@ -51,11 +50,11 @@ while True:
...
@@ -51,11 +50,11 @@ while True:
if
click
%
2
==
0
:
if
click
%
2
==
0
:
play_button
=
stop_img
play_button
=
stop_img
pygame
.
mixer
.
music
.
unpause
()
pygame
.
mixer
.
music
.
unpause
()
else
:
else
:
play_button
=
play_img
play_button
=
play_img
pygame
.
mixer
.
music
.
pause
()
pygame
.
mixer
.
music
.
pause
()
#判断鼠标是否点击的为播放按钮
if
x
>
420
and
x
<
520
and
y
>
350
and
y
<
400
:
# 下一曲
if
x
>
420
and
x
<
520
and
y
>
350
and
y
<
400
:
# 下一曲
num
+=
1
num
+=
1
if
num
>
len
(
music_list
)
-
1
:
if
num
>
len
(
music_list
)
-
1
:
...
@@ -67,7 +66,8 @@ while True:
...
@@ -67,7 +66,8 @@ while True:
click
+=
2
click
+=
2
else
:
else
:
click
+=
1
click
+=
1
music1
=
pygame
.
mixer
.
Sound
(
path
+
"
\\
"
+
music_list
[
num
])
music2
=
int
(
music1
.
get_length
())
if
x
>
120
and
x
<
220
and
y
>
350
and
y
<
400
:
# 上一曲
if
x
>
120
and
x
<
220
and
y
>
350
and
y
<
400
:
# 上一曲
num
-=
1
num
-=
1
if
num
<
0
:
if
num
<
0
:
...
@@ -79,22 +79,32 @@ while True:
...
@@ -79,22 +79,32 @@ while True:
click
+=
2
click
+=
2
else
:
else
:
click
+=
1
click
+=
1
music1
=
pygame
.
mixer
.
Sound
(
path
+
"
\\
"
+
music_list
[
num
])
music2
=
int
(
music1
.
get_length
())
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
num
+=
1
num
+=
1
if
num
>
len
(
music_list
)
-
1
:
if
num
>
len
(
music_list
)
-
1
:
num
=
0
num
=
0
#循环播放
pygame
.
mixer
.
music
.
load
(
path
+
"
\\
"
+
music_list
[
num
])
pygame
.
mixer
.
music
.
load
(
path
+
"
\\
"
+
music_list
[
num
])
pygame
.
mixer
.
music
.
play
()
pygame
.
mixer
.
music
.
play
()
music1
=
pygame
.
mixer
.
Sound
(
path
+
"
\\
"
+
music_list
[
num
])
music2
=
int
(
music1
.
get_length
())
#获取歌曲总长度
new_logo
=
pygame
.
transform
.
rotate
(
logo_img
,
a
)
new_logo
=
pygame
.
transform
.
rotate
(
logo_img
,
a
)
newRact
=
new_logo
.
get_rect
(
center
=
(
320
,
200
))
newRact
=
new_logo
.
get_rect
(
center
=
(
320
,
200
))
pos
=
(
newRact
[
0
],
newRact
[
1
])
pos
=
(
newRact
[
0
],
newRact
[
1
])
play_time
=
pygame
.
mixer
.
music
.
get_pos
()
play_time
=
pygame
.
mixer
.
music
.
get_pos
()
#获取歌曲播放进度
play_time
=
int
(
play_time
/
1000
)
play_time
=
int
(
play_time
/
1000
)
play_m
=
play_time
//
60
play_m
=
play_time
//
60
play_s
=
play_time
%
60
play_s
=
play_time
%
60
#把时间转换为分、秒
if
play_s
<
10
:
play_s
=
"0"
+
str
(
play_s
)
#秒前加0
info
=
str
(
play_m
)
+
":"
+
str
(
play_s
)
info
=
str
(
play_m
)
+
":"
+
str
(
play_s
)
music_fen
=
music2
//
60
music_miao
=
music2
%
60
#把时间转换为分、秒
if
music_miao
<
10
:
music_miao
=
"0"
+
str
(
music_miao
)
#秒前加0
info2
=
str
(
music_fen
)
+
":"
+
str
(
music_miao
)
# 绘制画面
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
play_button
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
play_button
,
(
270
,
330
))
# 暂停按钮
...
@@ -104,9 +114,11 @@ while True:
...
@@ -104,9 +114,11 @@ while True:
if
play_button
==
stop_img
:
if
play_button
==
stop_img
:
a
+=
1
a
+=
1
else
:
else
:
a
+=
0
a
+=
0
#logo旋转
# 刷新画面
# 刷新画面
text
=
myfont
.
render
(
info
,
True
,(
0
,
0
,
0
))
text
=
myfont
.
render
(
info
,
True
,(
0
,
0
,
0
))
screen
.
blit
(
text
,(
50
,
440
))
screen
.
blit
(
text
,(
50
,
440
))
#渲染播放进度
k
=
myfont
.
render
(
"/"
+
info2
,
True
,(
0
,
0
,
0
))
screen
.
blit
(
k
,(
100
,
440
))
#渲染总时长
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
100000000000000000000000000000000000000
)
FPS
.
tick
(
100000000000000000000000000000000000000
)
#帧数
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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