def initUI(self): """ Inicialización de sus parámetros """ # Parte visual self.imagen = QtGui.QLabel(self) self.pixmapAct = QtGui.QPixmap('./imagenes/logoWeb.png') self.imagen.setPixmap(self.pixmapAct) self.media1 = Phonon.MediaSource('./videos/1.avi') self.media2 = Phonon.MediaSource('./videos/2.avi') self.video1.load(self.media1) self.video2.load(self.media2) # Layouts: self.layoutVideo1 = QtGui.QVBoxLayout() self.layoutVideo1.addWidget(self.imagen) self.layoutVideo1.addWidget(self.video1) self.layoutVideo1.addWidget(self.video2) self.layoutVideo1.setAlignment(self.imagen, QtCore.Qt.AlignHCenter) self.video1.setHidden(True) self.video2.setHidden(True) self.dataIntroLayout = QtGui.QHBoxLayout() self.passwd = QtGui.QLabel('Ingrese respuesta:') self.passwd.setFont(QtGui.QFont('SansSerif', 36)) self.intro = QtGui.QLineEdit() self.intro.setFont(QtGui.QFont('SansSerif', 36)) #self.intro.setDisplayFormat("dd/MM/yyyy") self.intro.setInputMask("99/99/9999") self.intro.setCursorPosition(0) self.digitalIntro = QtGui.QLCDNumber(self) self.digitalIntro.setDigitCount(10) self.digitalIntro.setMinimumWidth(180) self.digitalIntro.display(' - - ') self.digitalIntro.setMaximumHeight(90) self.dataIntroLayout.addWidget(self.passwd) self.dataIntroLayout.addWidget(self.digitalIntro) self.dataIntroLayout.addWidget(self.intro) if self.myLcd: self.intro.setHidden(True) else: self.digitalIntro.setHidden(True) self.layoutVideo1.addLayout(self.dataIntroLayout) self.setLayout(self.layoutVideo1) self.setMinimumHeight(450) #self.setGeometry(300, 300, 300, 150) # Algunas visualizaciones: self.setWindowIcon(QtGui.QIcon('./imagenes/logo.png')) self.setWindowTitle(self.titulo)
def __init__(self, parent): #QGLWidget.__init__(self, parent) super(Field, self).__init__(parent) self.setMinimumSize(1400, 525) # GL settings fmt = self.format() fmt.setDoubleBuffer( True ) # always double buffers anyway (watch nVidia setting, do not do it there also n 120 Hz mode) fmt.setSampleBuffers(True) fmt.setSwapInterval( 1) # 0: no sync to v-refresh, number of syncs to wait for self.setFormat(fmt) # PyQt if self.format().swapInterval() == -1: qWarning( "Setting swapinterval not possible, expect synching problems") if not self.format().doubleBuffer(): qWarning("Could not get double buffer; results will be suboptimal") self.extrapolationTime = 0 self.fadeFactor = 1.0 # no fade, fully exposed self.state = "sleep" self.requestSleep = False self.lifetime = 60 # audio self.mediaObject = Phonon.MediaObject(self) self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self) Phonon.createPath(self.mediaObject, self.audioOutput) self.mediaSourceBeep = Phonon.MediaSource("sound\sound2.wav") self.mediaSourceNoise = Phonon.MediaSource("sound\wgn.wav") self.mediaObject.setCurrentSource(self.mediaSourceNoise) ## self.mediaObject.play() ## self.homingText = pyttsx.init() ## self.homingText.say('Homing.') #self.beep = pyglet.resource.media('sound\beep-5.wav') self.moveString = "Reference" self.t0PreTrial = -1 # -1 for not currently pretrial, >=0 for start time of pretrial state self.t0Wait = -1 # -1 for not currently wait, >=0 for start time of wait (response phase) # shutter glasses try: self.shutter = buttonbox.Buttonbox() # optionally add port="COM17" self.openShutter(False, False) except Exception as e: print(e) # experimental conditions self.conditions = conditions.Conditions( dataKeys=['swapMoves', 'subject']) self.nInterval = 1 self.nBall = 24 # number of stars in ball
def next(self): lens = len(self.songlist) if self.songing == -5: self.songing = lens-1 if lens-self.songing>1: songUrl = self.songlist[self.songing+1] self.mediaObject.setCurrentSource(Phonon.MediaSource(songUrl)) self.mediaObject.play() self.songing = self.songing+1 else: songUrl = self.songlist[0] self.mediaObject.setCurrentSource(Phonon.MediaSource(songUrl)) self.mediaObject.play() self.songing = 0
def App(self): # 设置start按钮 self.start_button = QPushButton('Start', self) self.start_button.setFont(self.font) self.start_button.resize(200, 100) self.start_button.move(650, 100) #设置stop按钮 self.stop_button = QPushButton('Stop', self) self.stop_button.resize(200, 100) self.stop_button.move(650, 450) self.stop_button.setFont(self.font) # 设置名字显示 self.name_lable = QLineEdit(self) self.name_lable.move(100, 450) self.name_lable.resize(350, 100) self.name_lable.setText('这个人是谁呢?') self.name_lable.setAlignment(Qt.AlignCenter) self.name_lable.setFont(self.font) self.timer = QTimer(self) # 设置图片显示 self.image_lable = QLabel(self) #为图片显示设置一个画布 位置大小 self.image_lable.setGeometry(50, 50, 470, 300) #为图片设置属性 self.image_lable.setStyleSheet("border: 2px solid blue") defaultimage = 'images/开始点名.jpg' self.pnx = QPixmap(defaultimage) # 加载图片路径 self.image_lable.setPixmap(self.pnx) # 将图片显示画布上 self.image_lable.setScaledContents(True) # 图片自适应窗 # 设置开始和结束 # print(self.start_button.isEnabled()) True 可以点击为True 不可以点击为False self.start_button.clicked.connect(lambda: self.start_name()) self.stop_button.clicked.connect(lambda: self.stop()) self.stop_button.clicked.connect( lambda: self.btnsetenabled(self.start_button)) # 设置图片显示 self.start_music = Phonon.createPlayer( Phonon.MusicCategory, Phonon.MediaSource("music/start.mp3")) self.end_music = Phonon.createPlayer( Phonon.MusicCategory, Phonon.MediaSource("music/end.mp3"))
def play(self, voice): voice_id = get_voice_file(voice) if voice_id == None: return voice_file = os.path.join(common.editor_config.voice_dir, "%04d.mp3" % voice_id) if not os.path.isfile(voice_file): QtGui.QMessageBox.warning(self.parent, "Could Not Find File", u"Could not locate\n%s" % voice_file) return if self.player.state() in [ Phonon.LoadingState, Phonon.PausedState, Phonon.StoppedState ]: self.player.setCurrentSource(Phonon.MediaSource(voice_file)) self.player.play() else: # Don't try to compete with the changing of states, just request the player # stop and then tell it to play when we switch into a safer state. self.next = voice_file self.player.stop()
def main(argv): #Parse out the command line arguments parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=DESCRIPTION, epilog=EPILOG) parser.add_argument("-d", "--debug", action='store_true', help="Output test debug information") parser.add_argument("media", type=str, nargs=1, default="all", help="Media to load") args = parser.parse_args() if args.debug: print "Debug Enabled" debug = True media_source = args.media[0] app = QApplication(sys.argv) #vp = Phonon.VideoPlayer() vp = VP() media = Phonon.MediaSource(media_source) vp.load(media) vp.play() #vp.VideoWidget = VW() vp.show() sys.exit(app.exec_())
def set_data(self, dataset): """ Set data from input :param dataset: input data :return: Void """ if dataset is not None: self.info.setText('%d instances in input data set' % len(dataset)) self.data = dataset print(self.data.metas[:, 0]) if self.data.Y != []: self.file_names = [str(x) + "/" + str(y) for x, y in zip([i.get_class() for i in self.data], self.data.metas[:,0])] else: self.file_names = self.data.metas[:,0] self.files_combo.addItems(self.file_names) for string in self.data.metas[:, 1]: self.sources.append(Phonon.MediaSource(string)) if self.sources: self.metaInformationResolver.setCurrentSource(self.sources[0]) else: self.info.setText( 'No data on input yet, waiting to get something.')
def __init__(self, parent = None): self.url = "http://listen.radionomy.com/dubsideradio" QtGui.QWidget.__init__(self, parent) self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) self.player = Phonon.createPlayer(Phonon.MusicCategory, Phonon.MediaSource(self.url)) self.player.setTickInterval(100) self.player.tick.connect(self.tock) self.play_pause = QtGui.QPushButton(self) self.icon = QtGui.QIcon() self.icon.addPixmap(QtGui.QPixmap(("image/play.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.play_pause.setIcon(self.icon) self.play_pause.setIconSize(QtCore.QSize(23, 24)) self.icon2 = QtGui.QIcon() self.icon2.addPixmap(QtGui.QPixmap(("image/pause.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.play_pause.setFlat(True) self.play_pause.clicked.connect(self.playClicked) self.player.stateChanged.connect(self.stateChanged) self.slider = Phonon.SeekSlider(self.player , self) self.setWindowIcon(self.icon) self.status = QtGui.QLabel(self) self.status.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) layout = QtGui.QHBoxLayout(self) layout.addWidget(self.play_pause) layout.addWidget(self.slider) layout.addWidget(self.status)
def setanimation(self): """ Randomly choose an animation and load it in the animation_player """ animation_str = 'animation_' + str(randint(1, N_ANIMATION)) + VIDEO_FORMAT animation_media = Phonon.MediaSource( os.path.join(ANIMATION_DIR, animation_str)) self.animation_player.load(animation_media)
def play_sound(self, clip): #plays the clicked sound self.mediaObject = Phonon.MediaObject(self) self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self) Phonon.createPath(self.mediaObject, self.audioOutput) # self.mediaObject.stateChanged.connect(self.handleStateChanged) self.mediaObject.setCurrentSource(Phonon.MediaSource(clip)) self.mediaObject.play()
def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) Ui_MainWindow.__init__(self) # QtGui.QDialog.__init__(self) self.setupUi(self) self.songModel = SongModel() self.initPlaylist() #初始化播放列表 self.player = Phonon.MediaObject() self.output = Phonon.AudioOutput(Phonon.MusicCategory) self.player.setCurrentSource(Phonon.MediaSource(self.url)) Phonon.createPath(self.player, self.output) # Phonon.createPath(self.mediaObject, self.player) self.player.setTickInterval(1000) self.player.tick.connect(self.tock) self.pushButton_play.clicked.connect(self.play_clicked) #播放按钮单击信号 self.player.stateChanged.connect(self.state_changed) #播放状态改变信号 self.player.finished.connect(self.finished) #播放结束信号 # Phonon.SeekSlider(self.player, self)#进度条 # self.seekSlider2 = Phonon.SeekSlider(self) self.seekSlider2.setMediaObject(self.player) self.seekSlider2.setTracking(True) # self.seekSlider2.show() # self.listWidget.itemSelectionChanged.connect(self.item_changed)#列表选项改变信号 self.listWidget.itemClicked.connect(self.item_clicked) #列表选项点击信号 self.pushButton_open_files.clicked.connect(self.open_files) #打开文件 self.pushButton_open_dir.clicked.connect(self.open_dir) #打开文件夹 self.pushButton_remove.clicked.connect(self.remove_item) #移除当前选中 self.volumeSlider.setAudioOutput(self.output) #音量控制器 self.pushButton_sort.clicked.connect(self.sort) #排序 self.pushButton_search.clicked.connect(self.search_music) #在线歌曲搜索 self.init_btn_enabled() self.dst = os.path.join(basedir, 'tmp.txt')
def finished(self): # print('finished') c_index = self.comboBox.currentIndex() #print(c_index) #单曲循环 if (c_index == 1): # self.url = self.songModel.get_url(self.listWidget.item(self.listWidget.currentRow()+1).text()) # print(self.url) self.player.play() #列表循环 if (c_index == 2): # self.player.pause() c_row = self.listWidget.currentRow() # print(c_row) if (c_row != -1): self.listWidget.setCurrentRow( (self.listWidget.currentRow() + 1) % self.listWidget.count()) else: self.url = self.listWidget.setCurrentRow(1) self.url = self.songModel.get_item( self.listWidget.item( self.listWidget.currentRow()).text())['url'] self.lrc = self.songModel.get_item( self.listWidget.item( self.listWidget.currentRow()).text())['lrc'] # print(self.url) self.player.setCurrentSource(Phonon.MediaSource(self.url)) Phonon.createPath(self.player, self.output) self.player.play() self.clr_lrc() if (self.lrc): self.show_lrc(self.lrc)
def premakni(self,ponor): self.player.stop() item=self.list[(self.dlg.listWidget.currentRow())] self.player.setCurrentSource(Phonon.MediaSource("")) if ponor!=None: ponor = str(ponor.replace("/", "\\")) ponor = str(ponor.replace(" ", "")) if not os.path.exists(ponor): os.makedirs(ponor) shutil.move(os.path.join(str(os.getcwd()),item), ponor) else: send2trash(os.path.join(os.getcwd(),item)) del self.list[self.dlg.listWidget.currentRow()] self.dlg.listWidget.takeItem(self.dlg.listWidget.currentRow()) if self.row + 1 < len(self.list): self.dlg.listWidget.setCurrentRow(self.row) self.play() else: self.player.stop() self.dlg.listWidget.setCurrentRow(0) if self.dlg.listWidget.currentRow() == -1: self.stop() self.player.clearQueue() self.dlg.Izvajalec.setText("") self.dlg.Naslov.setText("") self.dlg.Key.setText("") self.dlg.BPM.setText("KONEC") else: self.play()
def previewfile(self, path): global type if (type == 'Image'): self.stop.hide() self.start.hide() self.text_preview.setText("") self.tabWidget.setCurrentIndex(0) pixmap = QtGui.QPixmap(path) pixmap = pixmap.scaledToHeight(400) self.image_preview.setPixmap(pixmap) elif (type == 'Video'): self.stop.show() self.start.show() #self.gridLayout_3.addWidget(self.vp, 0, 0, 2, 2) self.tabWidget.setCurrentIndex(1) self.vp.show() media = Phonon.MediaSource(path) self.vp.load(media) self.vp.play() else: self.stop.hide() self.start.hide() self.image_preview.clear() self.scrollArea.setWidget(self.text_preview) self.tabWidget.setCurrentIndex(2) fileopen = open(path).read() self.text_preview.setText(fileopen)
def tagClicked(self, item): self.tabWidget_2.show() client = MongoClient() db = client.dr_schemas print item.text() cursor = db.file_schema.find({"Path": str(item.text())}) for document in cursor: if document['Type'] == 'Image': self.stop_2.hide() self.start_2.hide() self.text_preview_2.setText("") self.tabWidget_2.setCurrentIndex(0) pixmap = QtGui.QPixmap(document['Path']) pixmap = pixmap.scaledToHeight(200) self.image_preview_2.setPixmap(pixmap) elif document['Type'] == 'Text': self.stop_2.hide() self.start_2.hide() self.image_preview_2.clear() self.scrollArea_2.setWidget(self.text_preview_2) self.tabWidget_2.setCurrentIndex(2) fileopen = open(document['Path']).read() self.text_preview_2.setText(fileopen) elif document['Type'] == 'Video': self.stop_2.show() self.start_2.show() #self.gridLayout_3.addWidget(self.vp, 0, 0, 2, 2) self.tabWidget_2.setCurrentIndex(1) self.vp_2.show() media = Phonon.MediaSource(document['Path']) self.vp_2.load(media) self.vp_2.play()
def on_clicked(self): print "recommend" x = rec() for i in self.fulltable: print i #line = x currentRow = 0 for line in x: titleItem = QtGui.QTableWidgetItem(line[1]) titleItem.setFlags(titleItem.flags() ^ QtCore.Qt.ItemIsEditable) artistItem = QtGui.QTableWidgetItem(line[2]) artistItem.setFlags(artistItem.flags() ^ QtCore.Qt.ItemIsEditable) artistItem.setTextAlignment(QtCore.Qt.AlignLeft) albumItem = QtGui.QTableWidgetItem(line[3]) albumItem.setFlags(albumItem.flags() ^ QtCore.Qt.ItemIsEditable) timeItem = QtGui.QTableWidgetItem(str(line[4])) timeItem.setFlags(timeItem.flags() ^ QtCore.Qt.ItemIsEditable) timeItem.setTextAlignment(QtCore.Qt.AlignCenter) self.resource.append(Phonon.MediaSource(line[5])) #self.resource.append(line[5]) self.recTable.insertRow(currentRow) self.recTable.setItem(currentRow, 0, titleItem) self.recTable.setItem(currentRow, 1, artistItem) self.recTable.setItem(currentRow, 2, albumItem) self.recTable.setItem(currentRow, 3, timeItem) self.recTable.setRowHeight(currentRow, 50) currentRow = currentRow + 1
def startPlay(self): if not self.started: self.ui.statusbar.clearMessage() self.started = True self.isLabelClearable = True self.ui.label.clear() self.ui.l_total.hide() #self.ui.l_answer.setText('Your answer') self.ui.le_answer.clear() self.ui.le_answer.setEnabled(False) self.ui.pb_check.setEnabled(False) self.ui.pb_settings.setEnabled(False) self.count = 0 # generate sequence if self.replay: self.replay = False else: self.makeHistory() self.noscore = False self.ui.pb_replay.setEnabled(False) # change pb_start to 'Stop' when starting display self.ui.pb_start.setText(self.tr('&Stop')) self.ui.pb_start.setToolTip(self.tr('Stop the sequence')) if IS_PHONON_AVAILABLE: if self.speech and IS_ESPEAK_INSTALLED: self.player.stop() self.connect(self.player, QtCore.SIGNAL('finished()'), self.clearLabel) elif self.annoying_sound: self.disconnect(self.player, QtCore.SIGNAL('finished()'), self.clearLabel) self.player.setCurrentSource(Phonon.MediaSource(ANNOYING_SOUND)) if self.hands_free: self.ui.l_answer.setEnabled(False) # wait 1s before starting the display self.timerUpdateLabel.setInterval(1000) self.timerUpdateLabel.start() else: # then stop it self.started = False self.isLabelClearable = False self.timerUpdateLabel.stop() if self.hands_free: if IS_PHONON_AVAILABLE: self.disconnect(self.player, QtCore.SIGNAL('finished()'), self.restartPlay) self.connect(self.player, QtCore.SIGNAL('finished()'), self.clearLabel) self.timerShowAnswer.stop() self.timerRestartPlay.stop() self.ui.l_answer.setEnabled(True) self.ui.l_total.hide() self.ui.pb_settings.setEnabled(True) self.ui.gb_number.setTitle('#') self.ui.pb_start.setText(self.tr('&Start')) self.ui.pb_start.setToolTip(self.tr('Start a sequence')) self.ui.label.clear() if options.verbose: print if self.speech and IS_SOUND_WORKING: self.player.stop() if not self.hands_free: # reset history self.history = []
def open_screen(self): # Initializes screen with selected screen object, opens thread # when run screen = self.screens[self.lwScreen.currentRow()] dialog = customdialog.ViewDialog(screen, self._del_view_dialog) self.view_dialogs[screen.name] = dialog dialog.show() self.refresh_tab_buts() # Create new thread if screen is a Video object if type(screen) is svdevices.Video: # Initialize Phonon multimedia objects media_src = Phonon.MediaSource(screen.link) media_obj = Phonon.MediaObject(dialog) media_obj.setCurrentSource(media_src) video_widget = Phonon.VideoWidget(dialog) video_widget.setMinimumSize(640, 480) dialog.vLayout.addWidget(video_widget) Phonon.createPath(media_obj, video_widget) video_widget.show() worker = Worker(self._handle_video, media_obj, video_name=screen.name) self.threadpool.start(worker)
def __init__(self): QtGui.QMainWindow.__init__(self) #song to play self.mediaObject = Phonon.MediaObject(self) self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self) Phonon.createPath(self.mediaObject, self.audioOutput) path = "D:\UTM\Anul 2\Semestrul 2\MIDPS\Lab2\Pink.mp3" self.mediaObject.setCurrentSource(Phonon.MediaSource(path)) self.mediaObject.play() Ui_MainWindow.__init__(self) self.setWindowTitle("Calculator") self.setWindowIcon(QtGui.QIcon('Pink.png')) self.setupUi(self) numbers = [ self.button0, self.button1, self.button2, self.button3, self.button4, self.button5, self.button6, self.button7, self.button8, self.button9 ] operations = [self.plus, self.minus, self.mul, self.div, self.equal] for i in numbers: i.clicked.connect(self.Nums) for i in operations: i.clicked.connect(self.Operations) self.plus_minus.clicked.connect(self.Plus_Minus) self.point.clicked.connect(self.Point) self.power.clicked.connect(self.Power) self.sqrt.clicked.connect(self.Sqrt) self.clear.clicked.connect(self.C)
def execute(self): if self.encodeRadio.isChecked() == True: # Check that both the file list and the output file string contains something if len(self.fileList) >= 1 and len(self.outputFile) >= 1: # Pass the file list and output file string to the lhaudio function and encode the files lhaudio.encode(self.fileList, self.outputFile) # Clear both lists self.listClear() # Set the current source to be played to the newly encoded file self.mediaObject.setCurrentSource( Phonon.MediaSource(self.outputFile)) else: print("Select valid input file(s) and output directory") elif self.decodeRadio.isChecked() == True: if len(self.fileList) == 1: if len(self.outputDir) >= 1: lhaudio.decode(self.fileList[0], self.outputDir) self.listClear() # Update the time self.now = datetime.datetime.now() else: print("Choose a valid output directory") else: print("You need to decode one file") else: print("Uh oh, select mode")
def __init__(self, url, parent=None): self.url = url QtGui.QWidget.__init__(self, parent) self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) self.player = Phonon.VideoPlayer(Phonon.VideoCategory, self) self.player.load(Phonon.MediaSource(self.url)) self.player.mediaObject().setTickInterval(100) self.player.mediaObject().tick.connect(self.tock) self.play_pause = QtGui.QPushButton(self) self.play_pause.setText("Play") #self.play_pause.setIcon(QtGui.QIcon(':/icons/player_play.svg')) self.play_pause.clicked.connect(self.playClicked) self.player.mediaObject().stateChanged.connect(self.stateChanged) self.slider = Phonon.SeekSlider(self.player.mediaObject(), self) self.status = QtGui.QLabel(self) self.status.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.download = QtGui.QPushButton("Download", self) self.download.clicked.connect(self.fetch) topLayout = QtGui.QVBoxLayout(self) topLayout.addWidget(self.player) layout = QtGui.QHBoxLayout(self) layout.addWidget(self.play_pause) layout.addWidget(self.slider) layout.addWidget(self.status) layout.addWidget(self.download) topLayout.addLayout(layout) self.setLayout(topLayout)
def play(self): if self.curState != 'playing': if self.path != self.cancion_actual.cancion.archivo: self.path = self.cancion_actual.cancion.archivo self.phonon.setCurrentSource(Phonon.MediaSource(self.path)) self.phonon.play() self.curState = 'playing'
def loadmedia(self, media_path): media = Phonon.MediaSource(media_path) if media.type() == 1: logging.error('Invalid Media Source: {}'.format(media_path)) print('Invalid Media Source: {}'.format(media_path)) else: self.vid_player.load(media)
def atras(self): if self.curState != 'paused': self.stop() self.cancion_actual = self.cancion_actual.prev self.path = self.cancion_actual.cancion.archivo self.phonon.setCurrentSource(Phonon.MediaSource(self.path)) self.play()
def DataSetChanged(self, int): fname = self.dataSetNames[int] fdata = self.fileData[fname] file = fdata['File'] mat = scipy.io.loadmat(file) fld = fdata['Field'] self.mat = mat[fld] self.UpdateData(self.IMUIndex) if fdata.has_key('Video'): self.videoFile = fdata['Video'] #self.Media = self.Instance.media_new(unicode(self.videoFile)) #self.MediaPlayer.set_media(self.Media) #self.Media.parse() #self.MediaPlayer.play() self.videoSrc = Phonon.MediaSource(self.videoFile) self.videoPlayer.load(self.videoSrc) self.videoPlayer.play() self.videoPlayer.pause() self.videoPlayer.seek(0) self.videoLength = self.videoPlayer.mediaObject().totalTime() totalFrames = 59.94 * self.videoLength / 1000 self.positionSlider.setMaximum(ceil(totalFrames)) self.positionSlider.setSliderPosition(0) self.positionSlider.setSingleStep(1) self.positionSlider.setPageStep(30) else: self.videoFile = None self.setupAllAxis() #self.comboData.setCurrentIndex(0) self.IMUIndex = self.comboIMU.currentIndex() self.UpdateData(self.IMUIndex)
def __init__(self, url, parent=None): #url参数就是你的MP3地址 self.url = url QtGui.QWidget.__init__(self, parent) #设置一些窗口尺寸的策略,不用设置也会有默认策略,干脆注释了,无影响 # self.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Preferred) #创建一个音乐播放器 这是一种简单的方法,功能自然也是很单一,貌似只能实现简单的单首歌曲播放(希望我没有猜错,),更灵活的是使用AudioOutput,MediaObject等方法实现 self.player = Phonon.createPlayer(Phonon.MusicCategory, Phonon.MediaSource(url)) #下面这句话真没搞懂,谷歌了一下 多次尝试没反应 干脆把他注释了。。不影响程序 # self.player.setTickInterval(100) self.player.tick.connect(self.tock) #播放进度改变触发事件 self.play_pause = QtGui.QPushButton(self) #播放按钮 self.play_pause.setIcon( QtGui.QIcon('icons/49heart.svg')) #设置播放按钮图标,jpg,png都可以 self.play_pause.clicked.connect(self.playClicked) #播放按钮单击事件 self.player.stateChanged.connect(self.stateChanged) #播放状态改变触发事件 self.slider = Phonon.SeekSlider(self.player, self) #进度条 self.status = QtGui.QLabel(self) #Label组件用来显示播放的当前时间 self.status.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) #设置Label的对齐方式 左对齐或居中 layout = QtGui.QHBoxLayout(self) #水平布局 layout.addWidget(self.play_pause) #添加播放按钮 layout.addWidget(self.slider) #添加滑动条 layout.addWidget(self.status) #添加播放状态
def __init__(self): QtGui.QWidget.__init__(self) # media self.media = Phonon.MediaObject(self) self.media.stateChanged.connect(self.handleStateChanged) self.video = Phonon.VideoWidget(self) self.video.setMinimumSize(200, 200) self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self) Phonon.createPath(self.media, self.audio) Phonon.createPath(self.media, self.video) self.media.setCurrentSource(Phonon.MediaSource("Wildlife.wmv")) self.media.play() # control button self.button = QtGui.QPushButton('选择文件', self) self.button.clicked.connect(self.handleButton) # for display of time lapse self.info = QtGui.QLabel(self) # layout layout = QtGui.QGridLayout(self) layout.addWidget(self.video, 1, 1, 3, 3) layout.addWidget(self.info, 4, 1, 1, 3) layout.addWidget(self.button, 5, 1, 1, 3) # signal-slot, for time lapse self.thread = PollTimeThread(self) self.thread.update.connect(self.update)
def OpenFile(self): self.player.load(Phonon.MediaSource(self.filename)) self.clip = VideoFileClip(self.filename) # set the slider maximum to number of frames #self.nframes = (self.player.mediaObject().totalTime()/1000.)*self.clip.fps self.nframes = self.clip.duration * self.clip.fps self.PositionSlider.setMaximum(self.nframes)
def run(image_folder): #image_folder = 'images' video_name = 'video.avi' images = [img for img in os.listdir(image_folder) if img.endswith(".png")] frame = cv2.imread(os.path.join(image_folder, images[0])) height, width, layers = frame.shape video = cv2.VideoWriter(video_name,cv2.VideoWriter_fourcc('M','J','P','G'),1, (width,height)) for image in images: video.write(cv2.imread(os.path.join(image_folder, image))) cv2.destroyAllWindows() video.release() app = QtGui.QApplication(sys.argv) vp = Phonon.VideoPlayer() vp.show() media = Phonon.MediaSource('video.avi') vp.load(media) vp.play() vp.move(200,100) vp.setGeometry(50,50, 600, 600) sys.exit(app.exec_())
def openScore(self): name = QtGui.QFileDialog.getOpenFileNames( None, u'악보 선택 - .jhw 앞에 붙은 숫자가 클 수록 난이도가 쉽습니다. (20:쉬움 15:보통 10:어려움)', QtGui.QDesktopServices.storageLocation( QtGui.QDesktopServices.MusicLocation), "Score (*.jhw)") if not name: return else: self.score = name[0] if ".mp3" in self.score: self.source = self.score.split('.mp3')[0] + '.mp3' elif ".wma" in self.score: self.source = self.score.split('.wma')[0] + '.wma' elif ".wav" in self.score: self.source = self.score.split('.wav')[0] + '.wav' self.title = self.source.split('\\')[self.source.count('\\')] self.lineEdit.clear() self.lineEdit.append(self.score) self.lineEdit.append(u'악보 파일이 성공적으로 열렸습니다. 해당 악보에 맞는 음악을 로딩합니다.') if os.path.exists(self.source): self.player = Phonon.MediaObject() self.player.setCurrentSource(Phonon.MediaSource(self.source)) self.player.setTickInterval(100) self.player.tick.connect(self.tick) self.seekSlider.setMediaObject(self.player) self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory) Phonon.createPath(self.player, self.audioOutput) self.volumeSlider.setAudioOutput(self.audioOutput) self.sequencer() self.stop() self.lineEdit.append( u'음악파일이 성공적으로 로드되었습니다. 시작(F1)을 눌러 리듬게임을 시작하세요!') else: self.lineEdit.append(u'악보 파일에 해당하는 음악파일이 없습니다. 음악파일을 먼저 열어주세요')