Add subtitle control
This commit is contained in:
		
							parent
							
								
									81d9ddf606
								
							
						
					
					
						commit
						8944fdc291
					
				
					 1 changed files with 25 additions and 0 deletions
				
			
		|  | @ -234,6 +234,10 @@ class MainWindow(Gtk.ApplicationWindow): | |||
|         elif keyval == Gdk.keyval_from_name("Down"): | ||||
|             self._seek_relative(-60) | ||||
|             return True | ||||
|              | ||||
|         elif keyval == Gdk.keyval_from_name("j"): | ||||
|             self._cycle_subtitles() | ||||
|             return True | ||||
| 
 | ||||
|         return False | ||||
| 
 | ||||
|  | @ -272,6 +276,27 @@ class MainWindow(Gtk.ApplicationWindow): | |||
|             Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, new_pos | ||||
|         ) | ||||
| 
 | ||||
|     def _cycle_subtitles(self) -> None: | ||||
|         """Cycle through available subtitle tracks""" | ||||
|         playbin = self.pipeline.get_by_name("playbin") | ||||
|         if not playbin: | ||||
|             return | ||||
| 
 | ||||
|         # Get current subtitle track | ||||
|         current = playbin.get_property("current-text") | ||||
|         n_text = playbin.get_property("n-text") | ||||
| 
 | ||||
|         if n_text == 0: | ||||
|             self.show_overlay_text("No subtitles available") | ||||
|             return | ||||
| 
 | ||||
|         # Cycle to next track, wrapping around | ||||
|         next_track = (current + 1) % n_text | ||||
|         playbin.set_property("current-text", next_track) | ||||
|          | ||||
|         # Show the new track number | ||||
|         self.show_overlay_text(f"Subtitle track: {next_track}") | ||||
| 
 | ||||
|     def show_overlay_text(self, text: str, timeout_seconds: float = 1.0) -> None: | ||||
|         """Show text in a centered overlay that disappears after timeout""" | ||||
|         self.overlay_label.set_text(text) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue