예제 #1
0
	def onPlayerMessage(self, bus, message):
		t = message.type
		if (t == gst.MESSAGE_EOS):
			if (self.wTree.get_object("mnuiRepeatOne").get_active()):
				player.seek(0)
			else:
				if (self.wTree.get_object("mnuiRepeatAll").get_active()):
					queue.append(player.uri)
				# At the end of a stream, play next item from queue.
				# Or stop if the queue is empty.
				if (queue.length() > 0):
					self.playNext(atf=False)
				elif (self.wTree.get_object("mnuiQuitOnStop").get_active()):
					# Quit of the 'quit on stop' option is enabled.
					self.quit()
				else:
					# Otherwise, just stop.
					player.stop()
		
		elif (t == gst.MESSAGE_ERROR):
			# On an error, empty the currently playing file (also stops it).
			self.playFile(None)
			# Show an error about the failure.
			msg = message.parse_error()
			signals.emit('error', str(msg[0]) + '\n\n' + str(msg[1]), _('Error!'))
		elif (t == gst.MESSAGE_STATE_CHANGED and message.src == player.player):
			self.onPlayerStateChange(message)
		elif (t == gst.MESSAGE_TAG):
			# Tags!!
			self.setPlayingTitle(message.parse_tag())
예제 #2
0
	def playFile(self, file, stop=True):
		## Plays the file 'file' (Could also be a URI).
		# Stop the player if requested. (Required for playbin2 and
		# changing streams midway through another).
		if stop: player.stop()
		if (file == None):
			# If no file is to be played, set the URI to None, and the file to ""
			file = ""
		# Set the now playing label to the file to be played.
		self.nowPlyLbl.set_label(os.path.basename(urllib.url2pathname(file)))
		if (os.path.exists(file) or '://' in file):
			# If it's not already a uri, make it one.
			# Also escape any # characters in the filename
			file = useful.filenameToUri(file).replace('#', '%23')
			# Set the URI to the file's one.
			player.setURI(file)
			# Try to set the subtitle track if requested.
			if cfg.getBool('video/autosub'): subtitles.trySubs(file)
			# Add the file to recently opened files.
			gtk.recent_manager_get_default().add_item(file)
			# Start the player, if it isn't already running.
			if (not player.isPlaying()): player.play()
		
		elif (file != ""):
			# If none of the above, a bad filename was passed.
			print _("Something's stuffed up, no such file: %s") % (file)
			self.playFile(None)
예제 #3
0
파일: subtitles.py 프로젝트: gapan/whaawmp
	def addSubs(self, widget):
		# Add subtitles to the current file from a file dialogue.
		dlg = gtk.FileChooserDialog(_("Choose a subtitle stream."), self.window,
		                  buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
		                             gtk.STOCK_OPEN, gtk.RESPONSE_OK))
		# Use the same folder as the last file opened.
		dlg.set_current_folder(useful.lastFolder)
		res = dlg.run()
		
		if (res == gtk.RESPONSE_OK) and (player.player.get_property('n-video') >= 1):
			# If the response was 'OK' and there is a video track get the filename.
			file = dlg.get_filename()
			# We need to restart the player so the subtitles work.
			#played = player.getPlayed()
			player.stop()
			# Reset everything.
			player.player.set_property('uri', player.uri)
			player.player.set_property('suburi', useful.filenameToUri(file))
			player.player.set_property('subtitle-encoding', self.txtSubsEnc.get_text())
			player.play()
			#player.seek(played)
		
		dlg.destroy()