Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson5_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
bcf444b4
authored
Apr 09, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
19f22638
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
11 deletions
my_music.py
test.py
my_music.py
View file @
bcf444b4
import
pygame
import
pygame
from
pygame
import
locals
from
pygame
import
locals
import
os
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
# 创建窗口
# 创建窗口
...
@@ -10,18 +11,34 @@ play_img = pygame.image.load('play.png') # 播放按钮
...
@@ -10,18 +11,34 @@ play_img = pygame.image.load('play.png') # 播放按钮
stop_img
=
pygame
.
image
.
load
(
'stop.png'
)
# 暂停按钮
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
(
'歌曲4.ogg'
)
# 载入音乐
volume
=
0.2
volume
=
0.2
pygame
.
mixer
.
music
.
set_volume
(
volume
)
# 初始播放音量
pygame
.
mixer
.
music
.
set_volume
(
volume
)
# 初始播放音量
click
=
0
click
=
0
play_button
=
stop_img
play_button
=
stop_img
#定义一个音乐列表
music_list
=
[]
#定义索引变量
num
=-
1
#定义路径变量
path
=
"C:
\\
Users
\\
赵志
\\
Desktop
\\
音乐播放器"
filelist
=
os
.
listdir
(
path
)
#listdir(路径)获取指定路径下所有的文档,并且以列表的形式返回
for
i
in
filelist
:
if
i
[
-
4
:]
==
".wav"
or
i
[
-
4
:]
==
".ogg"
:
music_list
.
append
(
i
)
#定义角度变量
angle
=
0
#创建字体
my_font
=
pygame
.
font
.
Font
(
"neuropol.ttf"
,
18
)
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
# print(event)
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
exit
()
# 按键,控制声音大小
# 按键,控制声音大小
...
@@ -38,22 +55,66 @@ while True:
...
@@ -38,22 +55,66 @@ while True:
pygame
.
mixer
.
music
.
set_volume
(
volume
)
pygame
.
mixer
.
music
.
set_volume
(
volume
)
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
click
+=
1
if
event
.
button
==
1
:
if
click
%
2
==
0
:
x
,
y
=
event
.
pos
play_button
=
stop_img
if
x
>
270
and
x
<
370
and
y
>
330
and
y
<
430
:
pygame
.
mixer
.
music
.
unpause
()
click
+=
1
else
:
if
click
%
2
==
0
:
play_button
=
play_img
play_button
=
stop_img
pygame
.
mixer
.
music
.
pause
()
pygame
.
mixer
.
music
.
unpause
()
else
:
play_button
=
play_img
pygame
.
mixer
.
music
.
pause
()
#上一曲
if
x
>
120
and
x
<
220
and
y
>
350
and
y
<
400
:
num
-=
1
if
num
<
0
:
num
=
len
(
music_list
)
-
1
pygame
.
mixer
.
music
.
load
(
path
+
"
\\
"
+
music_list
[
num
])
# 载入音乐
pygame
.
mixer
.
music
.
play
()
#播放
click
=
0
play_button
=
stop_img
#下一曲
if
x
>
420
and
x
<
520
and
y
>
350
and
y
<
400
:
num
+=
1
if
num
>
len
(
music_list
)
-
1
:
num
=
0
pygame
.
mixer
.
music
.
load
(
path
+
"
\\
"
+
music_list
[
num
])
# 载入音乐
pygame
.
mixer
.
music
.
play
()
#播放
click
=
0
play_button
=
stop_img
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
num
+=
1
if
num
>
len
(
music_list
)
-
1
:
#len()列表长度
num
=
0
pygame
.
mixer
.
music
.
load
(
path
+
"
\\
"
+
music_list
[
num
])
# 载入音乐
pygame
.
mixer
.
music
.
play
()
pygame
.
mixer
.
music
.
play
()
"""
transform--转换模块--rotate(图片,角度)--返回旋转之后的图片
"""
#唱盘旋转
new_logo
=
pygame
.
transform
.
rotate
(
logo_img
,
angle
)
rect
=
new_logo
.
get_rect
(
center
=
(
320
,
200
))
#get_rect()获取到新图形的矩形的数据,以元组的形式返回(x坐标,y坐标,宽度,高度)
# print(rect)
pos
=
(
rect
[
0
],
rect
[
1
])
if
play_button
==
stop_img
:
angle
+=
1
#当前歌曲播放的进度
play_time
=
pygame
.
mixer
.
music
.
get_pos
()
#get_pos()获取到当前播放音乐所对应的时间,以毫秒返回
play_time
=
int
(
play_time
/
1000
)
play_m
=
play_time
//
60
#分钟
play_s
=
play_time
%
60
#秒数
info
=
str
(
play_m
)
+
":"
+
str
(
play_s
)
text
=
my_font
.
render
(
info
,
True
,(
255
,
255
,
255
))
# 绘制画面
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
play_button
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
play_button
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
logo_img
,
(
170
,
60
))
# 中间logo图
screen
.
blit
(
new_logo
,
pos
)
# 中间logo图
screen
.
blit
(
last_img
,
(
120
,
350
))
# 上一曲
screen
.
blit
(
last_img
,
(
120
,
350
))
# 上一曲
screen
.
blit
(
next_img
,
(
420
,
350
))
# 下一曲
screen
.
blit
(
next_img
,
(
420
,
350
))
# 下一曲
screen
.
blit
(
text
,(
120
,
440
))
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
\ No newline at end of file
test.py
0 → 100644
View file @
bcf444b4
"""
元组()---不可变的
列表[]---可变
"""
# tuple1=(100,200,300)
# x,y,z=tuple1#变量连续赋值
# print(x)
# print(y)
# print(z)
# import os
# path="C:\\Users\\赵志\\Desktop\\音乐播放器"
# filelist=os.listdir(path)#listdir(路径)获取指定路径下所有的文档,并且以列表的形式返回
# print(filelist)
print
(
8
/
3
)
print
(
8
//
3
)
#整除---》就近于比当前小数小的整数
print
(
-
1
//
2
)
\ 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