Example #1
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)
Example #2
0
	def restartTrack(self, widget=None):
		## Restarts the currently playing track.
		# Just seek to 0.
		player.seek(0)
		# Update the progrss bar.
		gobject.idle_add(self.progressUpdate)
		# Make sure the player is playing (ie. if it was paused etc)
		player.play()
Example #3
0
	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()