pyqt记录内容(音乐播放器)
#这是UI文件
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'AudioPlayerDialog.ui'
#
# Created: Wed Dec 04 10:46:57 2013
# by: PyQt4 UI code generator 4.9.6
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_AudioPlayerDialog(object):
def setupUi(self, AudioPlayerDialog):
AudioPlayerDialog.setObjectName(_fromUtf8("AudioPlayerDialog"))
AudioPlayerDialog.resize(453, 263)
AudioPlayerDialog.setMinimumSize(QtCore.QSize(310, 150))
AudioPlayerDialog.setMaximumSize(QtCore.QSize(453, 263))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(85, 170, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.AlternateBase, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(85, 170, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(85, 170, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(85, 170, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush)
AudioPlayerDialog.setPalette(palette)
AudioPlayerDialog.setFocusPolicy(QtCore.Qt.NoFocus)
AudioPlayerDialog.setAutoFillBackground(True)
self.centralwidget = QtGui.QWidget(AudioPlayerDialog)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.tableWidget = QtGui.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(330, 10, 101, 201))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 170, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
self.tableWidget.setPalette(palette)
self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
self.tableWidget.setColumnCount(1)
self.tableWidget.setRowCount(0)
item = QtGui.QTableWidgetItem()
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
item.setFont(font)
self.tableWidget.setHorizontalHeaderItem(0, item)
self.layoutWidget = QtGui.QWidget(self.centralwidget)
self.layoutWidget.setGeometry(QtCore.QRect(10, 150, 72, 30))
self.layoutWidget.setObjectName(_fromUtf8("layoutWidget"))
self.horizontalLayout_2 = QtGui.QHBoxLayout(self.layoutWidget)
self.horizontalLayout_2.setMargin(0)
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.LastToolButton = QtGui.QPushButton(self.layoutWidget)
self.LastToolButton.setEnabled(True)
self.LastToolButton.setMaximumSize(QtCore.QSize(40, 16777215))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/first.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.LastToolButton.setIcon(icon)
self.LastToolButton.setIconSize(QtCore.QSize(20, 20))
self.LastToolButton.setObjectName(_fromUtf8("LastToolButton"))
self.horizontalLayout_2.addWidget(self.LastToolButton)
self.NextToolButton = QtGui.QPushButton(self.layoutWidget)
self.NextToolButton.setEnabled(True)
self.NextToolButton.setMaximumSize(QtCore.QSize(40, 16777215))
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(_fromUtf8(":/last.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.NextToolButton.setIcon(icon1)
self.NextToolButton.setIconSize(QtCore.QSize(20, 20))
self.NextToolButton.setObjectName(_fromUtf8("NextToolButton"))
self.horizontalLayout_2.addWidget(self.NextToolButton)
self.layoutWidget1 = QtGui.QWidget(self.centralwidget)
self.layoutWidget1.setGeometry(QtCore.QRect(10, 20, 304, 118))
self.layoutWidget1.setObjectName(_fromUtf8("layoutWidget1"))
self.verticalLayout_2 = QtGui.QVBoxLayout(self.layoutWidget1)
self.verticalLayout_2.setMargin(0)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout_3 = QtGui.QHBoxLayout()
self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
self.label = QtGui.QLabel(self.layoutWidget1)
self.label.setObjectName(_fromUtf8("label"))
self.horizontalLayout_3.addWidget(self.label)
self.fileLineEdit = QtGui.QLineEdit(self.layoutWidget1)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(112, 111, 113))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(224, 223, 227))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
self.fileLineEdit.setPalette(palette)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(20)
font.setBold(True)
font.setWeight(75)
self.fileLineEdit.setFont(font)
self.fileLineEdit.setAutoFillBackground(True)
self.fileLineEdit.setText(_fromUtf8(""))
self.fileLineEdit.setReadOnly(True)
self.fileLineEdit.setObjectName(_fromUtf8("fileLineEdit"))
self.horizontalLayout_3.addWidget(self.fileLineEdit)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.seekSlider = phonon.Phonon.SeekSlider(self.layoutWidget1)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.seekSlider.sizePolicy().hasHeightForWidth())
self.seekSlider.setSizePolicy(sizePolicy)
self.seekSlider.setMinimumSize(QtCore.QSize(300, 21))
self.seekSlider.setObjectName(_fromUtf8("seekSlider"))
self.verticalLayout.addWidget(self.seekSlider)
self.verticalLayout_2.addLayout(self.verticalLayout)
self.horizontalLayout_4 = QtGui.QHBoxLayout()
self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.playToolButton = QtGui.QToolButton(self.layoutWidget1)
self.playToolButton.setMinimumSize(QtCore.QSize(40, 40))
self.playToolButton.setAutoFillBackground(True)
self.playToolButton.setAutoRaise(False)
self.playToolButton.setObjectName(_fromUtf8("playToolButton"))
self.horizontalLayout.addWidget(self.playToolButton)
self.stopToolButton = QtGui.QToolButton(self.layoutWidget1)
self.stopToolButton.setMinimumSize(QtCore.QSize(40, 40))
self.stopToolButton.setAutoRaise(False)
self.stopToolButton.setObjectName(_fromUtf8("stopToolButton"))
self.horizontalLayout.addWidget(self.stopToolButton)
self.horizontalLayout_4.addLayout(self.horizontalLayout)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_4.addItem(spacerItem)
self.volumeSlider = phonon.Phonon.VolumeSlider(self.layoutWidget1)
self.volumeSlider.setMinimumSize(QtCore.QSize(110, 22))
self.volumeSlider.setMaximumSize(QtCore.QSize(110, 22))
self.volumeSlider.setObjectName(_fromUtf8("volumeSlider"))
self.horizontalLayout_4.addWidget(self.volumeSlider)
self.verticalLayout_2.addLayout(self.horizontalLayout_4)
self.comboBox = QtGui.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(240, 150, 69, 22))
self.comboBox.setFocusPolicy(QtCore.Qt.WheelFocus)
self.comboBox.setObjectName(_fromUtf8("comboBox"))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
AudioPlayerDialog.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(AudioPlayerDialog)
self.menubar.setGeometry(QtCore.QRect(0, 0, 453, 23))
self.menubar.setObjectName(_fromUtf8("menubar"))
self.menuFile = QtGui.QMenu(self.menubar)
self.menuFile.setObjectName(_fromUtf8("menuFile"))
self.menuAudioEffects = QtGui.QMenu(self.menubar)
self.menuAudioEffects.setObjectName(_fromUtf8("menuAudioEffects"))
AudioPlayerDialog.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(AudioPlayerDialog)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
AudioPlayerDialog.setStatusBar(self.statusbar)
self.fileOpenAction = QtGui.QAction(AudioPlayerDialog)
self.fileOpenAction.setObjectName(_fromUtf8("fileOpenAction"))
self.fileExitAction = QtGui.QAction(AudioPlayerDialog)
self.fileExitAction.setObjectName(_fromUtf8("fileExitAction"))
self.fileOpenAction.setShortcut("Ctrl+q")
self.fileExitAction.setShortcut("Ctrl+e")
self.menuFile.addAction(self.fileOpenAction)
self.menuFile.addAction(self.fileExitAction)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuAudioEffects.menuAction())
self.retranslateUi(AudioPlayerDialog)
QtCore.QMetaObject.connectSlotsByName(AudioPlayerDialog)
def retranslateUi(self, AudioPlayerDialog):
AudioPlayerDialog.setWindowTitle(_translate("AudioPlayerDialog", "Audio Player", None))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("AudioPlayerDialog", "MUSIC", None))
self.label.setText(_translate("AudioPlayerDialog", "File:", None))
self.playToolButton.setText(_translate("AudioPlayerDialog", "Play", None))
self.stopToolButton.setText(_translate("AudioPlayerDialog", "Stop", None))
self.comboBox.setItemText(0, _translate("AudioPlayerDialog", "single", None))
self.comboBox.setItemText(1, _translate("AudioPlayerDialog", "circulate", None))
self.comboBox.setItemText(2, _translate("AudioPlayerDialog", "in turn", None))
self.menuFile.setTitle(_translate("AudioPlayerDialog", "File", None))
self.menuAudioEffects.setTitle(_translate("AudioPlayerDialog", "Effects", None))
self.fileOpenAction.setText(_translate("AudioPlayerDialog", "Open...", None))
self.fileExitAction.setText(_translate("AudioPlayerDialog", "Exit", None))
from PyQt4 import phonon
---------------------------
#这是程序文件
#encoding:utf-8
import ui_AudioPlayerDialog
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.Qt import QMainWindow, QApplication, SIGNAL, QFileDialog, QIcon, QAction
from PyQt4 import phonon
from PyQt4.phonon import Phonon
import os, sys
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
import sys
class Player(QtGui.QMainWindow):
def __init__(self,parent=None):
QMainWindow.__init__(self)
self.mediaSource = None
self.audioPath = ''
self.addedEffects = {}
self.effectsDict = {}
self.file = ''
self.ui = None
self.t = []
self.sources = []
self.mediaObj = phonon.Phonon.MediaObject(self)
self.audioSink = Phonon.AudioOutput(Phonon.MusicCategory, self)
self.audioPath = Phonon.createPath(self.mediaObj, self.audioSink)
self._createUI()
self._connect()
self.show()
def _createUI(self):
self.ui = ui_AudioPlayerDialog.Ui_AudioPlayerDialog()
self.ui.setupUi(self)
self.ui.retranslateUi(self)
#将按钮转换为图片
self.playIcon= QIcon("play.png")
self.pauseIcon= QIcon("pause.png")
stopIcon= QIcon("stop.png")
musicIcon= QIcon("music.png")
lastIcon= QIcon("first.png")
nextIcon= QIcon("last.png")
self.ui.playToolButton.setIcon(self.playIcon)
self.ui.stopToolButton.setIcon(stopIcon)
self.ui.LastToolButton.setIcon(lastIcon)
self.ui.NextToolButton.setIcon(nextIcon)
self.setWindowIcon(musicIcon)
self._setupEffectsMenu()
#激活进度条和声音
self.ui.seekSlider.setMediaObject(self.mediaObj)
self.ui.volumeSlider.setAudioOutput(self.audioSink)
def _setupEffectsMenu(self):
#添加效果菜单
availableEffects = Phonon.BackendCapabilities.availableAudioEffects()
for e in availableEffects:
effectName = e.name()
self.effectsDict[effectName] = e
action = QAction(effectName,self.ui.menuAudioEffects)
action.setCheckable(True)
self.ui.menuAudioEffects.addAction(action)
def _clearEffectsObjects(self):
#清除音频的效果
self.effectsDict.clear()
for effectName in self.addedEffects.keys():
effect = self.addedEffects[effectName]
self.audioPath.removeEffect(effect)
self.addedEffects.clear()
def closeEvent(self, evt):
#关闭事件
if self.mediaObj:
self.mediaObj.stop()
self.mediaObj = None
self._clearEffectsObjects()
QMainWindow.closeEvent(self, evt)
#创建信号槽事件
def _connect(self):
#打开文件
self.connect(self.ui.fileOpenAction,SIGNAL("triggered()"),self.openFileDialog)
#关闭窗体
self.connect(self.ui.fileExitAction,SIGNAL("triggered()"),self.close)
#改变音效
self.connect(self.ui.menuAudioEffects,SIGNAL("triggered(QAction*)"),self.changeAudioEffects)
#播放、暂停音乐
self.connect(self.ui.playToolButton,SIGNAL("clicked()"),self.playMedia)
#停止音乐
self.connect(self.ui.stopToolButton,SIGNAL("clicked()"),self.stopMedia)
#获取循环的方式
self.connect(self.ui.comboBox, QtCore.SIGNAL('activated(QString)'), self.order)
#下一首
self.connect(self.ui.LastToolButton, QtCore.SIGNAL('clicked()'),self.lastMedia)
#上一首
self.connect(self.ui.NextToolButton, QtCore.SIGNAL('clicked()'),self.nextMedia)
#实现播放的方式
self.mediaObj.aboutToFinish.connect(self.nextTrack)
#双击表头播放该音乐
self.ui.tableWidget.verticalHeader().sectionDoubleClicked.connect(self.VerSectionClicked)
def changeAudioEffects(self, action):
#增加播放效果
effectName = action.text()
if action.isChecked():
effectDescription = self.effectsDict[effectName]
effect = Phonon.Effect(effectDescription)
self.addedEffects[effectName] = effect
self.audioPath.insertEffect(effect)
else:
effect = self.addedEffects[effectName]
self.audioPath.removeEffect(effect)
del self.addedEffects[effectName]
#打开文件
def openFileDialog(self):
self.file = ''
self.file = \
unicode (QFileDialog.getOpenFileNames(
self,
u"Open Audio File","/video",
u"MP3 file (*.mp3);;wav(*.wav);;All Files (*.*);;"))
#获取文件输入表格中
self.f = self.file.split('/')
self.t.append(self.f[-1])
self.ui.tableWidget.setRowCount(len(self.t))
self.ui.tableWidget.setColumnCount(1)
for i in range(len(self.t)):
cnt = '%s'%(self.t[i])
newItem = QTableWidgetItem(cnt)
self.ui.tableWidget.setItem(i,0,newItem)
#播放音乐
if self.file:
self.p = 1
self.file = os.path.normpath(self.file)
self.ui.fileLineEdit.setText(self.file)
self.loadNewMedia()
self.playMedia()
#缓存新歌
def loadNewMedia(self):
self.p = 1
if self.mediaSource:
self.stopMedia()
del self.mediaSource
self.mediaSource = phonon.Phonon.MediaSource(self.file)
self.mediaObj.setCurrentSource(self.mediaSource)
#播放音乐
def playMedia(self):
if not self.okToPlayPauseStop():
return
if self.mediaObj is None:
print "Error playing Audio"
return
if self.p == 1:
self.mediaObj.play()
self.p = 0
self.ui.playToolButton.setIcon(self.pauseIcon)
else:
self.pauseMedia()
self.p = 1
self.ui.playToolButton.setIcon(self.playIcon)
#停止播放
def stopMedia(self):
if not self.okToPlayPauseStop():
return
self.mediaObj.stop()
#暂停播放
def pauseMedia(self):
self.mediaObj.pause()
#判断是否有文件在播放
def okToPlayPauseStop(self):
okToProceed = True
if self.mediaSource is None:
err="Choose an audio file from File->Open"
self.ui.fileLineEdit.setText(err)
okToProceed = False
return okToProceed
#播放选中的音乐
def VerSectionClicked(self,index):
self.file = 'F:/video/'+str(self.t[index])
self.p = 1
if self.file:
self.file = os.path.normpath(self.file)
self.ui.fileLineEdit.setText(self.file)
self.loadNewMedia()
self.playMedia()
#播放上一首
def lastMedia(self):
index = self.t.index(self.file.split('\\')[-1])
self.file = 'F:/video/'+self.t[index-1]
self.p = 1
if self.file:
self.file = os.path.normpath(self.file)
self.ui.fileLineEdit.setText(self.file)
self.loadNewMedia()
self.playMedia()
#播放下一首
def nextMedia(self):
index = self.t.index(self.file.split('\\')[-1])
self.file = 'F:/video/'+self.t[index+1]
self.p = 1
if self.file:
self.file = os.path.normpath(self.file)
self.ui.fileLineEdit.setText(self.file)
self.loadNewMedia()
self.playMedia()
#选择播放的方式
def nextTrack(self):
if self.text == 'circulate':
self.file = self.file
self.loadNewMedia()
self.playMedia()
if self.text == 'in turn':
self.nextMedia()
#获取播放方式的值
def order(self, text):
self.text = text
app = QApplication(sys.argv)
musicPlayer = Player()
app.exec_()
-------------
#self.tableWidget.setRowCount(row+1)#自己增加一行
row=self.tableWidget.rowCount()
self.tableWidget.setRowCount(row+1)
f1=QTableWidgetItem(f)
self.tableWidget.setItem(self.tableWidget.rowCount()-1,0,f1)
self.tableWidget.setHorizontalHeaderLabels([内容])
pyqt记录内容(音乐播放器)的更多相关文章
- 如何使用 pyqt 实现 Groove 音乐播放器
前言 Win10 自带了一款很好用的音乐播放器 -- Groove 音乐,但是只能支持本地音乐的播放.2020年3月底到4月底,自己一直在学习 PyQt5,然后从 2020年5月开始,着手使用 PyQ ...
- 音乐播放器 EasyMusic (一)
EasyMusic 一. 代码获取 github 上链接为 https://github.com/VincentWYJ/EasyMusic, 感兴趣的朋友可以同步下来看, 欢迎提出宝贵意见或建议. 1 ...
- Flex4/Flash开发在线音乐播放器 , 含演示地址
要求 必备知识 本文要求基本了解 Adobe Flex编程知识和JAVA基础知识. 开发环境 MyEclipse10/Flash Builder4.6/Flash Player11及以上 演示地址 演 ...
- 在线音乐播放器-----酷狗音乐api接口抓取
首先身为一个在线音乐播放器,需要前端和数据库的搭配使用. 在数据库方面,我们没有办法制作,首先是版权问题,再加上数据量.所以我们需要借用其他网络播放器的数据库. 但是这些在线播放器,如百度,酷狗,酷我 ...
- QT5:C++实现基于Multimedia的音乐播放器(序)
前段时间C++课设,决定做个播放器,于是参考了网上的代码后,做了个很简陋的音乐播放器(只写了MP3格式)出来,虽然功能甚少,但还是决定把过程记录一下. 成品如下图: 播放器功能: 上.下一首,音量控制 ...
- Android音乐播放器的设计与实现
目录 应用开发技术及开发平台介绍 应用需求分析 应用功能设计及其描述 应用UI展示 一.应用开发技术及平台介绍 ①开发技术: 本系统是采用面向对象的软件开发方法,基于Android studio开发平 ...
- SE Springer小组之《Spring音乐播放器》可行性研究报告一、二(转载)
此文转载自组员小明处~~ 1 引言 1.1编写目的 <软件工程>课程,我们团队计划开发一个音乐播放器.本文档是基于网络上现有的音乐播放器的特点,团队计划实现的音乐播放器功能和团队 ...
- (1)H5实现音乐播放器【正在播放-歌词篇】
近期闲来无事,就想着复习一下前端的东西,然后正好跟朋友搞了一个公共开放的音乐api接口,就想着写一个音乐播放器玩玩! 话不多说,直接上图,然后上代码 [播放器显示正在播放] 实现功能: 1:歌词随着歌 ...
- SE Springer小组《Spring音乐播放器》可行性研究报告一、二
1 引言 1.1编写目的 <软件工程>课程,我们团队计划开发一个音乐播放器.本文档是基于网络上现有的音乐播放器的特点,团队计划实现的音乐播放器功能和团队人员的综合实力等情况,说明该软件开发 ...
随机推荐
- Cocos2D-x权威指南: CCNode类方法:
5.1.4 画图节点CCNode和图层CCLayer CCNode中提供的方法,在public块中的方法主要有下面几个部分: 1.针对节点显示的属性信息读写 2.针对节点变换的属性信息读写 3.针对子 ...
- uva 10560 - Minimum Weight(数论)
题目连接:uva 10560 - Minimum Weight 题目大意:给出n,问说至少须要多少个不同重量的砝码才干称量1~n德重量,给出所选的砝码重量,而且给出k,表示有k个重量须要用上述所选的砝 ...
- Creating Apps With Material Design —— Defining Shadows and Clipping Views
View转载请注明 http://blog.csdn.net/eclipsexys 翻译自Developer Android,时间仓促,有翻译问题请留言指出,谢谢 定义阴影和裁减 材料设计引入了深度的 ...
- oracle 优化 —— 分区表
一.分区表简介 分区表类型:[范围分区].[列表分区] [hash分区] [这些分区的组合分区] 范围分区:以某一个范围进行分区.eg:时间段划分. 列表分区:以某一些几个值进行分区.eg:地区 ...
- UI基础视图----UIView总结
UIView是UIKit框架里面最基础的视图类,是UIResponder的子类,是UIApplication和UIViewController的兄弟类,是UIWindow,UILabel,UIImag ...
- LIS n*log(n)的理解
很多时候lis 用二分的方法比较方便 这里写一下他的原理 这里仅对严格的最长上升子序列做讨论 这里有两个数列 一个数列是 原串的数列 a1-an 另一个数列是最长上升子序列辅助数列 s数列的长度为 ...
- 棋盘上的距离 - Grids1657
棋盘上的距离 问题描述: 写一个程序,给定起始位置和目标位置,计算王.后.车.象从起始位置走到目标位置所需的最少步数. 王:横.直.斜都可以走,但每步限走一格. 后:横.直.斜都可以走,每步格数不受限 ...
- centos上安装rabbitmq并且python测试
把我的阿里云重置了一下,重新安装rabbitmq,看看会出现什么问题. 首先,把erlang环境安装一下,直接 yum list | grep erlang erlang.x86_64 R16B-03 ...
- AFNetworking 2.0 新特性讲解之AFHTTPSessionManager
AFNetworking 2.0 新特性讲解之AFHTTPSessionManager (2014-02-17 11:56:24) 转载▼ AFNetworking 2.0 相比1.0 API ...
- 《javascript权威指南》第9章 例9-8源码
//创建一个新的枚举类型 //不能使用它来创建该类型的新实例 function Enumeration(nameToValues){ var Enumeration = function(){thro ...