设为首页 加入收藏

TOP

【脚本项目源码】Python制作多功能音乐播放器,打造专属你的音乐播放器(二)
2023-07-25 21:27:58 】 浏览:56
Tags:项目源 Python 能音乐 乐播放
lf.cmb.currentIndex() == 1) and (not self.is_pause) and (not self.is_switching): if self.qlist.count() == 0: return if self.player.position() == self.player.duration(): self.is_switching = True self.setCurPlaying() self.slider.setValue(0) self.playMusic() self.is_switching = False # 随机播放 elif (self.cmb.currentIndex() == 2) and (not self.is_pause) and (not self.is_switching): if self.qlist.count() == 0: return if self.player.position() == self.player.duration(): self.is_switching = True self.qlist.setCurrentRow(random.randint(0, self.qlist.count()-1)) self.setCurPlaying() self.slider.setValue(0) self.playMusic() self.is_switching = False

代码有点多~~

剩余代码

'''打开文件夹'''
def openDir(self):
self.cur_path = QFileDialog.getExistingDirectory(self, "选取文件夹", self.cur_path)
if self.cur_path:
self.showMusicList()
self.cur_playing_song = ''
self.setCurPlaying()
self.label1.setText('00:00')
self.label2.setText('00:00')
self.slider.setSliderPosition(0)
self.is_pause = True
self.play_button.setText('播放')
'''导入setting'''
def loadSetting(self):
if os.path.isfile(self.settingfilename):
config = configparser.ConfigParser()
config.read(self.settingfilename)
self.cur_path = config.get('MusicPlayer', 'PATH')
self.showMusicList()
'''更新setting'''
def updateSetting(self):
config = configparser.ConfigParser()
config.read(self.settingfilename)
if not os.path.isfile(self.settingfilename):
config.add_section('MusicPlayer')
config.set('MusicPlayer', 'PATH', self.cur_path)
config.write(open(self.settingfilename, 'w'))
'''显示文件夹中所有音乐'''
def showMusicList(self):
self.qlist.clear()
self.updateSetting()
for song in os.listdir(self.cur_path):
if song.split('.')[-1] in self.song_formats:
self.songs_list.append([song, os.path.join(self.cur_path, song).replace('\\', '/')])
self.qlist.addItem(song)
self.qlist.setCurrentRow(0)
if self.songs_list:
self.cur_playing_song = self.songs_list[self.qlist.currentRow()][-1]
'''双击播放音乐'''
def doubleClicked(self):
self.slider.setValue(0)
self.is_switching = True
self.setCurPlaying()
self.playMusic()
self.is_switching = False
'''设置当前播放的音乐'''
def setCurPlaying(self):
self.cur_playing_song = self.songs_list[self.qlist.currentRow()][-1]
self.player.setMedia(QMediaContent(QUrl(self.cur_playing_song)))
'''提示'''
def Tips(self, message):
QMessageBox.about(self, "提示", message)
'''播放音乐'''
def playMusic(self):
if self.qlist.count() == 0:
self.Tips('当前路径内无可播放的音乐文件')
return
if not self.player.isAudioAvailable():
self.setCurPlaying()
if self.is_pause or self.is_switching:
self.player.play()
self.is_pause = False
self.play_button.setText('暂停')
elif (not self.is_pause) and (not self.is_switching):
self.player.pause()
self.is_pause = True
self.play_button.setText('播放')
'''上一首'''
def previewMusic(self):
self.slider.setValue(0)
if self.qlist.count() == 0:
self.Tips('当前路径内无可播放的音乐文件')
return
pre_row = self.qlist.currentRow()-1 if self.qlist.currentRow() != 0 else self.qlist.count() - 1
self.qlist.setCurrentRow(pre_row)
self.is_switching = True
self.setCurPlaying()
self.playMusic()
self.is_switching = False
'''下一首'''
def nextMusic(self):
self.slider.setValue(0)
if self.qlist.count()
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Django模板控制结构(for/forloop/.. 下一篇从0到1学Python丨图像平滑方法的..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目