Verified Commit 27ad0a47 authored by Todd Weaver's avatar Todd Weaver
Browse files

Only updating slider when duration and position are valid (e.g. > 0)

Adding a focus function that sets the flowboxchild as focus then the child box (this allows for re-grabbing focus)
Adding app volume that controls all the gstreamer players
Replacing the delayed grabbing focus for the focus function
Adding keypress events for reverse, forward, volume up/down
Adjusting can-focus to False for buttons that are in the player
Focusing player upon any keypress used for player
parent 62c3a855
......@@ -161,7 +161,7 @@ class ResultsBox(Gtk.Box):
position_value = float(position) / Gst.SECOND * self.percent
if int(duration) > 0:
if duration > 0 and position > 0:
viewed_seconds = int(position / Gst.SECOND)
remaining_seconds = int((duration - position) / Gst.SECOND)
viewed = self.get_readable_seconds(viewed_seconds)
......@@ -170,20 +170,16 @@ class ResultsBox(Gtk.Box):
self.time_viewed.set_label(viewed)
self.time_remaining.set_label(f"-{remaining}")
if int(position / Gst.SECOND) >= int(duration / Gst.SECOND):
if position / Gst.SECOND >= duration / Gst.SECOND:
self.null_out_player()
# is negative number when not successful, so put it to 0
if not success:
position_value = 0
try:
# block seek slider function so it doesn't loop itself
self.slider.handler_block_by_func(self.seek_slider)
self.slider.set_value(position_value)
self.slider.handler_unblock_by_func(self.seek_slider)
except:
return False
try:
# block seek slider function so it doesn't loop itself
self.slider.handler_block_by_func(self.seek_slider)
self.slider.set_value(position_value)
self.slider.handler_unblock_by_func(self.seek_slider)
except:
return False
return True
......@@ -283,8 +279,17 @@ class ResultsBox(Gtk.Box):
self.show_progress_icon('video')
self.download_video_uri(self.video_dl_uri)
def box_grab_focus(self):
if self.app_window.results_list.get_focus_child():
# grab the parent flowboxchild and focus it
# to snap it into frame
self.app_window.results_list.get_focus_child().grab_focus()
# grab the result box to enable future focus snapping
self.grab_focus()
@Gtk.Template.Callback()
def play_button(self, button):
self.box_grab_focus()
# loop through all child results pausing them
self.app_window.pause_all(self)
......@@ -303,6 +308,9 @@ class ResultsBox(Gtk.Box):
# allow seeking
self.slider.set_sensitive(True)
app_volume = self.app_window.volume.get_value()
self.player.set_property("volume", app_volume)
# update slider to track video time in slider
GLib.timeout_add_seconds(1, self.update_slider)
......@@ -312,6 +320,7 @@ class ResultsBox(Gtk.Box):
@Gtk.Template.Callback()
def pause_button(self, button):
self.box_grab_focus()
self.inactivate_player()
self.player.set_state(Gst.State.PAUSED)
......@@ -329,9 +338,6 @@ class ResultsBox(Gtk.Box):
self.poster_image.set_size_request(width, height)
self.video_widget.set_size_request(width, height)
def delay_grab(self):
self.grab_focus()
@Gtk.Template.Callback()
def fullscreen_button(self, button):
self.fullscreen.set_visible(False)
......@@ -351,9 +357,7 @@ class ResultsBox(Gtk.Box):
results_context.remove_class("results")
results_context.add_class("fullscreen")
# grabbing happens before resize completes
# adding a slight delay to grab focus after resize completes
GLib.timeout_add(50, self.delay_grab)
self.box_grab_focus()
# horizonal scrollbar, vertical scrollbar (do last)
scroller = self.app_window.scroller
......@@ -385,7 +389,7 @@ class ResultsBox(Gtk.Box):
scroller.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
scroller.set_kinetic_scrolling(True)
self.grab_focus()
self.box_grab_focus()
@Gtk.Template.Callback()
def seek_slider(self, scale):
......@@ -396,6 +400,31 @@ class ResultsBox(Gtk.Box):
Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT,
seek * Gst.SECOND / self.percent)
def reverse_keypress(self):
self.box_grab_focus()
if self.app_window.is_playing:
success, position = self.player.query_position(Gst.Format.TIME)
seek = 0
# extra fast keypresses yield a -1 for position
if position > 0:
if position / Gst.SECOND >= 10:
seek = position - (10 * Gst.SECOND)
self.player.seek_simple(Gst.Format.TIME,
Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, seek)
def forward_keypress(self):
self.box_grab_focus()
if self.app_window.is_playing:
p_success, position = self.player.query_position(Gst.Format.TIME)
d_success, duration = self.player.query_duration(Gst.Format.TIME)
seek = duration
# extra fast keypresses yield a -1 for position
if position > 0:
if position <= duration - (10 * Gst.SECOND):
seek = position + (10 * Gst.SECOND)
self.player.seek_simple(Gst.Format.TIME,
Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, seek)
def poll_mouse(self):
now_is = int(GLib.get_current_time())
if (int(now_is) - (self.last_move)) >= 1:
......
......@@ -115,13 +115,17 @@ class Search:
def check_video_playable_cb(self, session, results, video_meta):
if results.status_code != 200:
#print('Unplayable video file, trying next instance')
#print(video_meta['title'])
video_meta.pop('video_uri')
self.si_index += 1
if len(self.app_window.strong_instances) > self.si_index:
self.this_instance = self.app_window.strong_instances[self.si_index]
#print(self.this_instance)
self.get_video_details(video_meta)
else:
#print("Out of instances, breaking")
return False
if 'video_uri' in video_meta:
......
......@@ -18,13 +18,13 @@
<child>
<object class="GtkOverlay" id="video_overlay">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<child>
<object class="GtkBox" id="player_box">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="orientation">vertical</property>
......@@ -93,7 +93,7 @@
<object class="GtkButton" id="audio_dl">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Save Audio</property>
<property name="opacity">0.80</property>
<property name="halign">center</property>
......@@ -120,7 +120,7 @@
<object class="GtkButton" id="video_dl">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Save Video</property>
<property name="opacity">0.80</property>
<property name="halign">center</property>
......@@ -236,7 +236,7 @@
<object class="GtkButton" id="speed">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Adjust Speed</property>
<property name="opacity">0.80</property>
<property name="halign">center</property>
......@@ -271,7 +271,7 @@
<child>
<object class="GtkButton" id="fullscreen">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Fullscreen</property>
<property name="opacity">0.80</property>
<property name="halign">center</property>
......@@ -294,7 +294,7 @@
</child>
<child>
<object class="GtkButton" id="unfullscreen">
<property name="can-focus">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Unfullscreen</property>
<property name="opacity">0.80</property>
<property name="halign">center</property>
......@@ -368,7 +368,7 @@
<object class="GtkScale" id="slider">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="can-focus">False</property>
<property name="opacity">0.80</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
......
......@@ -3,6 +3,11 @@
<interface>
<requires lib="gtk+" version="3.20"/>
<requires lib="libhandy" version="1.2"/>
<object class="GtkAdjustment" id="volume_adjustment">
<property name="upper">1</property>
<property name="step-increment">.05</property>
<property name="page-increment">.1</property>
</object>
<template class="StreamWindow" parent="HdyApplicationWindow">
<property name="can-focus">False</property>
<property name="hexpand">False</property>
......@@ -43,6 +48,22 @@
</style>
</object>
</child>
<child>
<object class="GtkVolumeButton" id="volume">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="focus-on-click">False</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
<property name="adjustment">volume_adjustment</property>
<property name="value">0.90</property>
<property name="icons">audio-volume-muted-symbolic
audio-volume-high-symbolic
audio-volume-low-symbolic
audio-volume-medium-symbolic</property>
<signal name="value-changed" handler="volume_change" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImage" id="status_icon">
<property name="visible">True</property>
......@@ -164,8 +185,8 @@
<placeholder/>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="position">4</property>
</packing>
......
......@@ -35,6 +35,7 @@ class StreamWindow(Handy.ApplicationWindow):
__gtype_name__ = 'StreamWindow'
header_bar = Gtk.Template.Child()
volume = Gtk.Template.Child()
status_icon = Gtk.Template.Child()
search_bar_toggle = Gtk.Template.Child()
......@@ -141,15 +142,28 @@ class StreamWindow(Handy.ApplicationWindow):
@Gtk.Template.Callback()
def keypress_listener(self, widget, ev):
key = Gdk.keyval_name(ev.keyval)
focus_child = self.results_list.get_focus_child()
if focus_child:
# key values are from gdk/gdkkeysyms.h
key = Gdk.keyval_name(ev.keyval)
if key == "Escape":
focus_child.get_child().unfullscreen_button(None)
if key == "space":
elif key == "space":
self.play_pause_toggle(focus_child)
if key == "f":
elif key == "f":
self.fullscreen_toggle(focus_child)
elif key == "Up":
self.volume_up_keypress()
return True
elif key == "Down":
self.volume_down_keypress()
return True
elif key == "Left":
focus_child.get_child().reverse_keypress()
return True
elif key == "Right":
focus_child.get_child().forward_keypress()
return True
def pause_all(self, active_window):
flowboxes = self.results_list.get_children()
......@@ -183,3 +197,34 @@ class StreamWindow(Handy.ApplicationWindow):
def swallow_fullscreen_scroll_event(self, event, data):
if self.is_fullscreen:
return True
@Gtk.Template.Callback()
def volume_change(self, event, data):
self.volume_slider(event.get_value())
def volume_slider(self, volume_value):
children = self.results_list.get_children()
for child in children:
child.get_child().player.set_property("volume", volume_value)
def focus_child(self):
# grab focus of playing video on keypress
focus_child = self.results_list.get_focus_child()
if focus_child:
focus_child.get_child().box_grab_focus()
def volume_up_keypress(self):
current_volume = self.volume.get_value()
louder = 1.0
if current_volume <= 0.9:
louder = current_volume + 0.1
self.volume.set_value(louder)
self.focus_child()
def volume_down_keypress(self):
current_volume = self.volume.get_value()
quieter = 0
if current_volume >= 0.1:
quieter = current_volume - 0.1
self.volume.set_value(quieter)
self.focus_child()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment