Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson6_diy1
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
a0a64fe5
authored
Apr 04, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
94ce5011
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
2 deletions
my_music.py
my_music.py
View file @
a0a64fe5
...
...
@@ -13,6 +13,7 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮
last_img
=
pygame
.
image
.
load
(
'last.png'
)
# 上一曲按钮
next_img
=
pygame
.
image
.
load
(
'next.png'
)
# 下一曲按钮
logo_img
=
pygame
.
image
.
load
(
'logo.png'
)
# 下一曲按钮
basic_font
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
14
)
# 字体
path
=
r"C:\Users\Administrator\Desktop\python\pygame\音乐播放器(3)\level3-lesson6-diy1"
filelist
=
os
.
listdir
(
path
)
...
...
@@ -76,6 +77,10 @@ while True:
click
+=
2
else
:
click
+=
1
# 歌曲的时间
music1
=
pygame
.
mixer
.
Sound
(
path
+
"
\\
"
+
music_list
[
num
])
music_length
=
music1
.
get_length
()
music_length
=
int
(
music_length
)
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
num
+=
1
...
...
@@ -83,18 +88,40 @@ while True:
num
=
0
pygame
.
mixer
.
music
.
load
(
path
+
'
\\
'
+
music_list
[
num
])
pygame
.
mixer
.
music
.
play
()
# 歌曲的时间
music1
=
pygame
.
mixer
.
Sound
(
path
+
"
\\
"
+
music_list
[
num
])
music_length
=
music1
.
get_length
()
music_length
=
int
(
music_length
)
# +++++++++++++++++++++++++++++++++++++
# 旋转图片(注意:这里要搞一个新变量,存储旋转后的图片)
new_logo
=
pygame
.
transform
.
rotate
(
logo_img
,
angle
)
# 校正旋转图片的中心点
if
play_button
==
stop_img
:
angle
+=
1
newRect
=
new_logo
.
get_rect
(
center
=
(
320
,
200
))
# print(newRect) # rect(170, 65, 300, 270) 左上角坐标、图片大小
pos
=
(
newRect
[
0
],
newRect
[
1
])
# 歌曲的时间长度
music_m
=
music_length
//
60
music_s
=
music_length
%
60
if
music_s
<
10
:
music_s
=
"0"
+
str
(
music_s
)
info2
=
str
(
music_m
)
+
":"
+
str
(
music_s
)
# 歌曲播放进度时间
play_time
=
pygame
.
mixer
.
music
.
get_pos
()
play_time
=
int
(
play_time
/
1000
)
play_m
=
play_time
//
60
# 分
play_s
=
play_time
%
60
# 秒
if
play_s
<
10
:
play_s
=
"0"
+
str
(
play_s
)
info
=
str
(
play_m
)
+
":"
+
str
(
play_s
)
angle
+=
1
# +++++++++++++++++++++++++++++++++++++
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
...
...
@@ -104,5 +131,11 @@ while True:
screen
.
blit
(
last_img
,
(
120
,
350
))
# 上一曲
screen
.
blit
(
next_img
,
(
420
,
350
))
# 下一曲
# 绘制时间进度
scoreSurf
=
basic_font
.
render
(
info
,
True
,
(
255
,
255
,
255
))
screen
.
blit
(
scoreSurf
,
(
120
,
440
))
scoreSurf2
=
basic_font
.
render
(
"/"
+
info2
,
True
,
(
0
,
0
,
0
))
screen
.
blit
(
scoreSurf2
,
(
170
,
440
))
# 刷新画面
pygame
.
display
.
update
()
\ No newline at end of file
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