import sys app = QApplication(sys.argv) player = QMediaPlayer() file = QFile('/Users/junahyung/emomovie/SimpsonSen.mp4') print(1) isOpen = file.open(QIODevice.ReadOnly) print(2) buffer = QBuffer() buffer.open(QIODevice.ReadWrite) print(3) player.setMedia(QMediaContent(), buffer) print(4) if isOpen: while not file.atEnd(): temp = file.readLine() # temp = QByteArray.fromBase64(temp) buffer.write(temp) print(5) videoWidget = QVideoWidget() print(6) player.setVideoOutput(videoWidget) print(7) videoWidget.show() print(8)
def populateForm(self, title): #title is the primary key listArray = queries("""SELECT title, status, style, duration, description, location, project, variation_another_song, timestamp from songs WHERE title = ?""", (title,)) print(listArray) if len(listArray) != 0: title = listArray[0][0] status = listArray[0][1] styles = [] styleArray = listArray[0][2] if styleArray != None: if "," in styleArray: styles = styleArray.split(",") else: styles.append(styleArray) duration = listArray[0][3] description = listArray[0][4] location = listArray[0][5] project = listArray[0][6] variation_another_song = listArray[0][7] timestamp = listArray[0][8] else: title = None status = None styles = None duration = None description = None location = None project = None variation_another_song = None timestamp = None if title != None: self.titleEdit.setText(title) self.statusBox.addItems(["Select...", "Demo", "WIP", "Idea", "Unfinished song", "EQ", "Master", "Finished"]) if status != None: self.statusBox.setCurrentText(status) if timestamp != None: self.dateEdit.setDateTime(datetime.strptime(timestamp, '%d/%m/%Y %H:%M')) else: self.dateEdit.setDateTime(datetime.now())#default styleArray = queries("select style from songs where style is not null") """ print(styleArray) if styleArray != None: styleArray = styleArray[0][0] if "," in styleArray: styles = styleArray.split(",") else: styles.append(styleArray)""" stylesArray = [] query = queries("select style from songs where style is not null") if len(query) != 0: for style in query: stylesMiniArray = style[0].split(",") stylesMiniArray = list(filter(None, stylesMiniArray)) for item in stylesMiniArray: if item not in stylesArray: if item != '': stylesArray.append(item) self.x = 0 self.y = 0 if len(stylesArray) != 0: for style in stylesArray: print("style", style) checkBox = QCheckBox(style) self.styleLayout.addWidget(checkBox, self.x, self.y) self.checkBoxPositionAsignment() self.addStyle() if styles!= None: if len(styles) != 0: for style in styles: for checkbox in self.styleGroupBox.children(): if isinstance(checkbox, QCheckBox): if checkbox.text() == style: checkbox.setChecked(True) if duration != None: time = QTime(0,0,0) self.durationLine.setTime(time.addSecs(duration)) projectsArray = ["Select..."] projectsArrayQuery = queries("SELECT project from songs") if len(projectsArrayQuery) != 0: for project in projectsArrayQuery[0]: if project not in projectsArray: projectsArray.append(project) if project != None: self.projectComboBox.setCurrentText(project) if variation_another_song != None: self.variationLine.setText(variation_another_song) if description != None: self.descriptionTextEdit.setText(description) available = False if location != None: self.locationLine.setText(location) if len(self.locationLine.text()) != 0: try: self.playlist = QMediaPlaylist() self.playlist.addMedia(QMediaContent(QUrl.fromLocalFile(location))) self.mediaPlayer.setPlaylist(self.playlist) except: pass available = True#I know this is stupid but just in case self.slider.setVisible(available) self.playButton.setVisible(available) self.stopButton.setVisible(available)
def init_ui(self): #create media player object #canvas = Bar(self, width=9, height=4) #canvas.move(0, 0) self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface) #create videowidget object videowidget = QVideoWidget() #self.mediaPlayer.setVideoOutput(videowidget) #create open button openBtn = QPushButton('Open Video') openBtn.clicked.connect(self.open_file) self.videobutton = QPushButton('start') self.videobutton.clicked.connect(self.record) #create button for playing self.playBtn = QPushButton() #self.playBtn.setEnabled(False) self.playBtn.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.playBtn.clicked.connect(self.play_video) #create slider self.slider = QSlider(Qt.Horizontal) self.slider.setRange(0, 0) self.slider.sliderMoved.connect(self.set_position) #create label self.label = QLabel() self.label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) #create hbox layout hboxLayout = QHBoxLayout() hboxLayout.setContentsMargins(0, 0, 0, 0) #set widgets to the hbox layout hboxLayout.addWidget(openBtn) hboxLayout.addWidget(self.videobutton) hboxLayout.addWidget(self.playBtn) hboxLayout.addWidget(self.slider) #create vbox layout vboxLayout = QVBoxLayout() vboxLayout.addWidget(videowidget) vboxLayout.addLayout(hboxLayout) vboxLayout.addWidget(self.label) self.setLayout(vboxLayout) self.mediaPlayer.setVideoOutput(videowidget) #media player signals self.mediaPlayer.stateChanged.connect(self.mediastate_changed) self.mediaPlayer.positionChanged.connect(self.position_changed) self.mediaPlayer.durationChanged.connect(self.duration_changed) self.mediaPlayer.error.connect(self.handle_errors) self.label.setText("Ready") self.mediaPlayer.setMedia( QMediaContent( QUrl.fromLocalFile( "C:/Users/brahm/OneDrive/Desktop/face exp node/రాష్ట్రపతి పాలన ఎప్పుడు, ఎందుకు విధిస్తారు_ ఆర్టికల్ 356 ఏం చెబుతోంది_ - BBC New.wmv" )))
def __load_sound_file(self): sound_file_path = self.__saved_settings.get('chosen_sound') if sound_file_path in self.NO_SOUND_VALS: sound_file_path = '' media_content = QMediaContent(QUrl.fromLocalFile(sound_file_path)) self.__player.setMedia(media_content)
def loadUrl(self, url): mc = QMediaContent(url) self.mediaPlayer.setMedia(mc)
def set_video(self, file_name, width, height): self.view.mediaPlayer.setMedia( QMediaContent(QUrl.fromLocalFile(file_name))) QtUtil.central(self.view.videoWidget, self.view.videoBackgroundWidget, width, height, 2, 2) self.on_play()
def init_ui(self): layout = QVBoxLayout() self.setLayout(layout) self.setWindowTitle(self.fullPath) self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.videoWidget = QVideoWidget() self.playButton = QPushButton() self.playButton.setEnabled(True) self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.playButton.setFixedWidth(100) self.playButton.setFixedHeight(50) self.playButton.clicked.connect(self.play) self.trimButton = QPushButton("Trim") self.trimButton.setFixedWidth(150) self.trimButton.setFixedHeight(50) self.trimButton.clicked.connect(self.trimVid) self.positionSlider = QSlider(QtCore.Qt.Horizontal) self.positionSlider.setRange(0, 0) self.positionSlider.sliderMoved.connect(self.setPosition) self.rangeSlider = qrangeslider.QRangeSlider() self.rangeSlider.setRange(0, 0) self.rangeSlider.endValueChanged.connect(self.adjustForEnd) self.rangeSlider.startValueChanged.connect(self.adjustForStart) self.rangeSlider.setFixedHeight(15) self.startTimeInput = QTimeEdit() self.endTimeInput = QTimeEdit() self.startTimeInput.setDisplayFormat('hh:mm:ss.zzz') self.endTimeInput.setDisplayFormat('hh:mm:ss.zzz') self.startTimeInput.timeChanged.connect(self.startInputChanged) self.endTimeInput.timeChanged.connect(self.endInputChanged) self.mediaPlayer.setMedia( QMediaContent(QtCore.QUrl.fromLocalFile(self.fullPath))) layout.addWidget(self.videoWidget) self.mediaPlayer.setVideoOutput(self.videoWidget) self.mediaPlayer.setNotifyInterval(10) self.mediaPlayer.stateChanged.connect(self.mediaStateChanged) self.mediaPlayer.positionChanged.connect(self.positionChanged) self.mediaPlayer.durationChanged.connect(self.durationChanged) controlLayout = QVBoxLayout() controlLayout.setContentsMargins(0, 0, 0, 0) controlLayout.addWidget(self.rangeSlider) controlLayout.addWidget(self.positionSlider) timeInputLayout = QHBoxLayout() timeInputLayout.addWidget(self.playButton) timeInputLayout.addWidget(self.startTimeInput) timeInputLayout.addWidget(self.endTimeInput) timeInputLayout.addWidget(self.trimButton) controlLayout.addLayout(timeInputLayout) layout.addLayout(controlLayout) self.mediaPlayer.play() self.resize(1024, 700) self.show()
def start_new_file(self): self.mediaPlayer.setMedia( QMediaContent(QUrl.fromLocalFile(self.media_path))) self.mediaPlayer.pause() self.update_icon() self.enable_video_controls(True)
def __init__(self, project=None, parent=None): super(VideoWindow, self).__init__(parent) self.project = project self.setWindowTitle("Video") self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface) videoWidget = QVideoWidget() self.videoWidget = videoWidget self.playButton = QPushButton() self.playButton.setEnabled(False) self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.playButton.clicked.connect(self.play) self.positionSlider = QSlider(Qt.Horizontal) self.positionSlider.setRange(0, 0) self.positionSlider.sliderMoved.connect(self.setPosition) self.errorLabel = QLabel() self.errorLabel.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) # Create new action # openAction = QAction(QIcon('open.png'), '&Open', self) # openAction.setShortcut('Ctrl+O') # openAction.setStatusTip('Open movie') # openAction.triggered.connect(self.openFile) # Create exit action # exitAction = QAction(QIcon('exit.png'), '&Exit', self) # exitAction.setShortcut('Ctrl+Q') # exitAction.setStatusTip('Exit application') # exitAction.triggered.connect(self.exitCall) # Create menu bar and add action # menuBar = self.menuBar() # fileMenu = menuBar.addMenu('&File') # #fileMenu.addAction(newAction) # fileMenu.addAction(openAction) # fileMenu.addAction(exitAction) # Create layouts to place inside widget controlLayout = QHBoxLayout() controlLayout.setContentsMargins(0, 0, 0, 0) controlLayout.addWidget(self.playButton) controlLayout.addWidget(self.positionSlider) layout = QVBoxLayout() layout.addWidget(videoWidget) layout.addLayout(controlLayout) # layout.addWidget(self.errorLabel) # Hide error Label # Set widget to contain window contents self.setLayout(layout) self.mediaPlayer.setVideoOutput(videoWidget) self.mediaPlayer.stateChanged.connect(self.mediaStateChanged) self.mediaPlayer.positionChanged.connect(self.positionChanged) self.mediaPlayer.durationChanged.connect(self.durationChanged) self.mediaPlayer.error.connect(self.handleError) if self.project.current_animal.video_files: self.current_file = self.project.current_animal.video_files[0] self.current_time_range = [self.project.current_animal.video_init_time[0], self.project.current_animal.video_init_time[0] + self.project.current_animal.video_duration[0]] self.mediaPlayer.setMedia(QMediaContent(QUrl.fromLocalFile(self.current_file))) self.playButton.setEnabled(True) else: self.current_file = '' self.current_time_range = [0,0]
def playAudio(self, word): self.mp.setMedia( QMediaContent(QUrl.fromLocalFile(word["pronunciation"]))) self.playSignal.emit()
def OnPlayTrack(self, track_dir, player): App.start_playlist_from_track(self.id) media = QMediaContent(QUrl.fromLocalFile(track_dir)) player.setMedia(media) player.play()
url = "http://dict.youdao.com/dictvoice" country = "2" #1-english,2-american params = {"audio": word["spelling"], "type": country} data = parse.urlencode(params).encode(encoding="utf-8") req = request.Request(url, data) with request.urlopen(req) as response: filePath = config.pronDataPath + word["spelling"] + "_yd.wav" with open(filePath, "wb") as f: f.write(response.read()) word["pronunciation"] = filePath def check(self, fileName): # to do: check whether file is exist return True if __name__ == "__main__": from PyQt5.QtWidgets import QApplication from PyQt5.QtMultimedia import QMediaPlayer import sys app = QApplication(sys.argv) mp = QMediaPlayer() mp.setMedia( QMediaContent(QUrl.fromLocalFile(config.pronDataPath + "hello_yd.wav"))) audioManager = AudioManager(mp) word = {"spelling": "hello", "pronunciation": "notExist"} audioManager.prononce(word) app.exec()
def start_ins(self): self.ui.Video.setAspectRatioMode(Qt.IgnoreAspectRatio) self.mediaPlayer.setMedia(QMediaContent(QUrl.fromLocalFile(instruction_path))) self.ui.Video_Button.setEnabled(True) self.play()
def play(self, url): self.media_player.setMedia(QMediaContent(QUrl.fromLocalFile(url))) self.media_player.play()
def __init__(self, fname, volume): super().__init__(None) self.player = QMediaPlayer() self.player.setMedia(QMediaContent(QUrl(fname))) self.player.setVolume(volume)
def play(self): if self._source: self.media_player.setMedia( QMediaContent(QUrl.fromLocalFile(self._source))) self.media_player.play()
def load_video(self, path): self.media_player.setMedia(QMediaContent(QUrl.fromLocalFile(path)))
def set_song(self, file_location: str): self.file_location = file_location self.mp3 = mutagen.mp3.EasyMP3(file_location) self.content = QMediaContent(QUrl.fromLocalFile(file_location))
def loadFilm(self, f): self.mediaPlayer.setMedia(QMediaContent(QUrl.fromLocalFile(f))) self.playButton.setEnabled(True) self.mediaPlayer.play() print(self.mediaPlayer.media().canonicalResource().resolution())
def play_voice(self, url): """播放音频""" content = QMediaContent(QtCore.QUrl(url)) self.player.setMedia(content) print(url) self.player.play()
def __init__(self, parent=None): """Initialize the QMainWindow widget. The window title, window icon, and window size are initialized here as well as the following widgets: QMediaPlayer, QMediaPlaylist, QMediaContent, QMenuBar, QToolBar, QLabel, QPixmap, QSlider, QDockWidget, QListWidget, QWidget, and QVBoxLayout. The connect signals for relavant widgets are also initialized. """ super(MusicPlayer, self).__init__(parent) self.setWindowTitle('Mosaic') window_icon = utilities.resource_filename('mosaic.images', 'icon.png') self.setWindowIcon(QIcon(window_icon)) self.resize(defaults.Settings().window_size, defaults.Settings().window_size + 63) # Initiates Qt objects to be used by MusicPlayer self.player = QMediaPlayer() self.playlist = QMediaPlaylist() self.playlist_location = defaults.Settings().playlist_path self.content = QMediaContent() self.menu = self.menuBar() self.toolbar = QToolBar() self.art = QLabel() self.pixmap = QPixmap() self.slider = QSlider(Qt.Horizontal) self.duration_label = QLabel() self.playlist_dock = QDockWidget('Playlist', self) self.library_dock = QDockWidget('Media Library', self) self.playlist_view = QListWidget() self.library_view = library.MediaLibraryView() self.library_model = library.MediaLibraryModel() self.preferences = configuration.PreferencesDialog() self.widget = QWidget() self.layout = QVBoxLayout(self.widget) self.duration = 0 self.playlist_dock_state = None self.library_dock_state = None # Sets QWidget() as the central widget of the main window self.setCentralWidget(self.widget) self.layout.setContentsMargins(0, 0, 0, 0) self.art.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) # Initiates the playlist dock widget and the library dock widget self.addDockWidget(defaults.Settings().dock_position, self.playlist_dock) self.playlist_dock.setWidget(self.playlist_view) self.playlist_dock.setVisible(defaults.Settings().playlist_on_start) self.playlist_dock.setFeatures(QDockWidget.DockWidgetClosable) self.addDockWidget(defaults.Settings().dock_position, self.library_dock) self.library_dock.setWidget(self.library_view) self.library_dock.setVisible( defaults.Settings().media_library_on_start) self.library_dock.setFeatures(QDockWidget.DockWidgetClosable) self.tabifyDockWidget(self.playlist_dock, self.library_dock) # Sets the range of the playback slider and sets the playback mode as looping self.slider.setRange(0, self.player.duration() / 1000) self.playlist.setPlaybackMode(QMediaPlaylist.Sequential) # OSX system menu bar causes conflicts with PyQt5 menu bar if sys.platform == 'darwin': self.menu.setNativeMenuBar(False) # Initiates Settings in the defaults module to give access to settings.toml defaults.Settings() # Signals that connect to other methods when they're called self.player.metaDataChanged.connect(self.display_meta_data) self.slider.sliderMoved.connect(self.seek) self.player.durationChanged.connect(self.song_duration) self.player.positionChanged.connect(self.song_position) self.player.stateChanged.connect(self.set_state) self.playlist_view.itemActivated.connect(self.activate_playlist_item) self.library_view.activated.connect(self.open_media_library) self.playlist.currentIndexChanged.connect(self.change_index) self.playlist.mediaInserted.connect(self.initialize_playlist) self.playlist_dock.visibilityChanged.connect( self.dock_visiblity_change) self.library_dock.visibilityChanged.connect(self.dock_visiblity_change) self.preferences.dialog_media_library.media_library_line.textChanged.connect( self.change_media_library_path) self.preferences.dialog_view_options.dropdown_box.currentIndexChanged.connect( self.change_window_size) self.art.mousePressEvent = self.press_playback # Creating the menu controls, media controls, and window size of the music player self.menu_controls() self.media_controls() self.load_saved_playlist()
def loadMedia(self, fullPath): self.setMedia(QMediaContent(QUrl.fromLocalFile(fullPath))) self.stop()
def load_film(self, f): self.media_player.setMedia(QMediaContent(QUrl.fromLocalFile(f))) self.playButton.setEnabled(True) self.media_player.pause()
def get_another_challenge(self, stage=1, anew=False): if anew: self.pick_challenge() eyes = "OPEN" if self.current_eyes_open else "CLOSED" if stage > 3: stage = 1 if self.current_log_saving: # if we are in a new cycle and the log was being recorded with open( "out/" + self.current_challenge.get_key() + "_" + eyes + "_" + self.current_challenge.get_name() + "_" + str(int(time.time())) + ".json", "w") as f: data = {} for sample in self.current_samples: # we write the current stage samples data[str(sample[0])] = {} data[str(sample[0])]['e'] = str(sample[1]) # eeg data[str(sample[0])]['a'] = str(sample[2]) # aux json_data = json.dumps(data) f.write(str(json_data)) self.current_samples = [] # and initiate the list again local = QUrl.fromLocalFile('bell_tibet.mp3') media = QMediaContent(local) self.mediaPlayer.setMedia(media) self.mediaPlayer.play() self.get_another_challenge(stage, True) # we begin anew, overflow self.current_log_saving = False # turn off log saving, we later turn it on in the Stage 3 self.prompter_toggle_lights( True) # default: color red is on - do nothing, yet self.signal_start_duration.emit( self.current_challenge.get_duration(stage), self.current_challenge.get_original_duration(stage)) self.current_original_duration = self.current_challenge.get_original_duration( stage) self.current_movie = self.current_challenge.get_data(stage) self.progress.set_stage(stage) self.progress.set_remaining(self.current_challenge.get_duration(stage)) if stage == 1: self.signal_label_text.emit(self.current_challenge.text) self.camera_thread.quit( ) # turn of the camera if it is not already self.current_eyes_open = random.choice([True, False]) # eyes always closed in meditation if self.current_challenge.get_key() == "meditation": self.current_eyes_open = False self.signal_eyes_open.emit(self.current_eyes_open) elif stage == 2: self.signal_eyes_open.emit(self.current_eyes_open) self.initiate_movie() else: # Stage 3 - we begin collecting samples AND recording the web camera self.current_log_saving = True self.camera_thread.set_details( self.current_challenge.get_duration(stage), "out/" + self.current_challenge.get_key() + "_" + eyes + "_" + self.current_challenge.get_name() + "_" + str(int(time.time()))) self.camera_thread.start() self.initiate_movie() self.prompter_toggle_lights(False) self.progress.start()
def videoyuOynat(self): d = self.kelimeListesi[self.referansSayi] print(d) self.mediaPlayer.setMedia( QMediaContent(QUrl.fromLocalFile("VIDEOLAR/{}.MP4".format(d)))) self.mediaPlayer.play()
def mp3_to_data(mp3_path: str) -> QMediaContent: return QMediaContent(QUrl.fromLocalFile(mp3_path))
def play(self, localpath): print('localpath:{}'.format(localpath)) self.mediaPlayer.stop() self.mediaPlayer.setMedia(QMediaContent(QUrl.fromLocalFile(localpath))) self.mediaPlayer.play() print('开始播放{}'.format('23333'))
def insertMedia(self, index, songInfo_dict: dict): """ 在指定位置插入要播放的歌曲 """ super().insertMedia( index, QMediaContent(QUrl.fromLocalFile(songInfo_dict['songPath']))) self.playlist.insert(index, songInfo_dict)
def videoyuOynat(self, video): self.mediaPlayer.setMedia( QMediaContent(QUrl.fromLocalFile(video))) self.mediaPlayer.play()
def set_source(self, audio_path): url = QUrl.fromLocalFile(audio_path) media = QMediaContent(url) self.setNotifyInterval(35) self.setMedia(media)