#这是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([内容])