此代码是上一期的改版
需要用到的Python库有
.pygame
2.time
3.xmusic(我自己写的用来做音乐索引)
.colorama(美观)
推荐使用pip安装
方法: pip install 库
# -* encoding:utf-8 *-
import xmusic
import colorama
from colorama import Fore
# 音乐库
# Music
while True:
colorama.init()
text = '''
----↓歌曲列表↓---- 1.02的爱恋
2.奇迹再现
3.花降
4.布鲁克的心跳 '''
print(Fore.RED + text) M_1 = {'02的爱恋'}
M_2 = {'奇迹再现'}
M_3 = {'花降'}
M_4 = {'布鲁克的心跳'}
# 要查的歌名
name_m = input('输入要搜索的歌名:')
request = input("点击任意键播放...")
print('——————————————————————————')
if name_m in M_1:xmusic.M_02deailian()
if name_m in M_2:xmusic.M_qijizaixian()
if name_m in M_3:xmusic.M_huajiang()
if name_m in M_4:xmusic.M_bulukedexintiao()
s = input('输入[y]继续听歌 其他退出:')
if s == 'y':print()
else:break
导入步骤:
1.下载xmusic(点击蓝色字体下载)
2.把下载好的文件放到Python目录里的Lib
运行效果:
xmusic库:代码如下
#奇迹再现
import pygame
import time def M_qijizaixian():
f = open('Music\qjzx\qj.txt', 'r', encoding='UTF-8')
f = f.read()
print(f)
file = r'Music\qjzx\qjzx.mp3' # mp3文件路径
pygame.mixer.init()
print("正在播放", file)
track = pygame.mixer.music.load(file)
pygame.mixer.music.play()
time.sleep(3 ) # 播放时间
pygame.mixer.music.stop()
return #02的爱恋
def M_02deailian():
f = open('Music\\02\\geci.txt', 'r', encoding='UTF-8')
f = f.read()
print(f)
file = r'Music\02\02.mp3' # mp3文件路径
pygame.mixer.init()
print("正在播放", file)
track = pygame.mixer.music.load(file)
pygame.mixer.music.play()
time.sleep(304) # 播放时间
pygame.mixer.music.stop()
#花降
def M_huajiang():
f = open('Music\\花降\\hj.txt', 'r', encoding='UTF-8')
f = f.read()
print(f)
file = r'Music\花降\ナブナ - 花降らし.mp3' # mp3文件路径
pygame.mixer.init()
print("正在播放", file)
track = pygame.mixer.music.load(file)
pygame.mixer.music.play()
time.sleep(304) # 播放时间
pygame.mixer.music.stop() #
def M_bulukedexintiao():
f = open('Music\\布鲁克\\布鲁克的心跳.txt', 'r', encoding='UTF-8')
f = f.read()
print(f)
file = r'Music\布鲁克\海小贼 - 布鲁克的心跳(Cover:萧亚轩).mp3' # mp3文件路径
pygame.mixer.init()
print("正在播放", file)
track = pygame.mixer.music.load(file)
pygame.mixer.music.play()
time.sleep(130) # 播放时间
pygame.mixer.music.stop()
原创 不经允许禁止转载