介绍
这是一个基于Python Flask的网页播放器,你可以使用它来管理和播放你的音乐文件。应用程序具有以下功能:
- 显示音乐列表和封面图片
- 点击音乐列表中的歌曲封面图片即可播放对应的音乐
- 支持音乐的播放、暂停和控制
准备工作
确保你的电脑上安装了Python和Flask,并且有一些音乐文件(.mp3)和封面图片(.jpg)保存在本地目录中。
实现
Python Flask 应用程序
import os
from flask import Flask, send_from_directory, render_template
app = Flask(__name__)
# Directory where your songs and covers are located
SONG_DIR = "D:/song"
def get_songs_with_covers():
songs = [f for f in os.listdir(SONG_DIR) if f.endswith('.mp3')]
covers = [f for f in os.listdir(SONG_DIR) if f.endswith('.jpg')]
# Sort songs and covers for consistent ordering
songs.sort()
covers.sort()
songs_with_covers = []
for song in songs:
# Assuming cover image has the same name as the song
cover_name = os.path.splitext(song)[0] + '.jpg