mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-29 21:21:12 +00:00
gst-play: Allow switching to previous tracks
Implement case sensitive key-press handling, and make 'V', 'A', 'S' switch to the previous video, audio, or subtitle track. The lower-case keypress cycles to the next track, as before Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1841>
This commit is contained in:
parent
00f773bd10
commit
dde9e4e288
1 changed files with 58 additions and 19 deletions
|
@ -501,6 +501,8 @@ play_bus_msg (GstBus * bus, GstMessage * msg, gpointer user_data)
|
||||||
case GST_NAVIGATION_EVENT_KEY_PRESS:
|
case GST_NAVIGATION_EVENT_KEY_PRESS:
|
||||||
{
|
{
|
||||||
const gchar *key;
|
const gchar *key;
|
||||||
|
const gchar *key_input;
|
||||||
|
gchar key_adjusted[2];
|
||||||
|
|
||||||
if (gst_navigation_event_parse_key_event (ev, &key)) {
|
if (gst_navigation_event_parse_key_event (ev, &key)) {
|
||||||
GST_INFO ("Key press: %s", key);
|
GST_INFO ("Key press: %s", key);
|
||||||
|
@ -529,7 +531,21 @@ play_bus_msg (GstBus * bus, GstMessage * msg, gpointer user_data)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
keyboard_cb (key, user_data);
|
/* In the case of a simple single-char input,
|
||||||
|
* make it lower or upper as needed, and
|
||||||
|
* send that instead */
|
||||||
|
if (key[0] != '\0' && key[1] == '\0') {
|
||||||
|
if (play->shift_pressed)
|
||||||
|
key_adjusted[0] = g_ascii_toupper (key[0]);
|
||||||
|
else
|
||||||
|
key_adjusted[0] = g_ascii_tolower (key[0]);
|
||||||
|
key_adjusted[1] = '\0';
|
||||||
|
key_input = key_adjusted;
|
||||||
|
} else {
|
||||||
|
key_input = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboard_cb (key_input, user_data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1158,7 +1174,8 @@ play_get_nth_stream_in_collection (GstPlay * play, guint index,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
play_cycle_track_selection (GstPlay * play, GstPlayTrackType track_type)
|
play_cycle_track_selection (GstPlay * play, GstPlayTrackType track_type,
|
||||||
|
gboolean forward)
|
||||||
{
|
{
|
||||||
const gchar *prop_cur, *prop_n, *prop_get, *name;
|
const gchar *prop_cur, *prop_n, *prop_get, *name;
|
||||||
gint cur = -1, n = -1;
|
gint cur = -1, n = -1;
|
||||||
|
@ -1270,19 +1287,34 @@ play_cycle_track_selection (GstPlay * play, GstPlayTrackType track_type)
|
||||||
|
|
||||||
if (play->is_playbin3) {
|
if (play->is_playbin3) {
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
if (cur < 0)
|
if (forward) {
|
||||||
cur = 0;
|
if (cur < 0)
|
||||||
else
|
cur = 0;
|
||||||
cur = (cur + 1) % (n + 1);
|
else
|
||||||
|
cur = (cur + 1) % (n + 1);
|
||||||
|
} else {
|
||||||
|
if (cur <= 0)
|
||||||
|
cur = n;
|
||||||
|
else
|
||||||
|
cur = (cur - 1) % (n + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
g_object_get (play->playbin, prop_cur, &cur, prop_n, &n, "flags",
|
g_object_get (play->playbin, prop_cur, &cur, prop_n, &n, "flags",
|
||||||
&cur_flags, NULL);
|
&cur_flags, NULL);
|
||||||
|
|
||||||
if (!(cur_flags & flag))
|
if (forward) {
|
||||||
cur = 0;
|
if (!(cur_flags & flag))
|
||||||
else
|
cur = 0;
|
||||||
cur = (cur + 1) % (n + 1);
|
else
|
||||||
|
cur = (cur + 1) % (n + 1);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (cur <= 0)
|
||||||
|
cur = n;
|
||||||
|
else
|
||||||
|
cur = (cur - 1) % (n + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n < 1) {
|
if (n < 1) {
|
||||||
|
@ -1382,9 +1414,9 @@ print_keyboard_help (void)
|
||||||
"-", N_("decrease playback rate")}, {
|
"-", N_("decrease playback rate")}, {
|
||||||
"d", N_("change playback direction")}, {
|
"d", N_("change playback direction")}, {
|
||||||
"t", N_("enable/disable trick modes")}, {
|
"t", N_("enable/disable trick modes")}, {
|
||||||
"a", N_("change audio track")}, {
|
"A/a", N_("change to previous/next audio track")}, {
|
||||||
"v", N_("change video track")}, {
|
"V/v", N_("change to previous/next video track")}, {
|
||||||
"s", N_("change subtitle track")}, {
|
"S/s", N_("change to previous/next subtitle track")}, {
|
||||||
"0", N_("seek to beginning")}, {
|
"0", N_("seek to beginning")}, {
|
||||||
"k", N_("show keyboard shortcuts")},};
|
"k", N_("show keyboard shortcuts")},};
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
|
@ -1413,9 +1445,12 @@ keyboard_cb (const gchar * key_input, gpointer user_data)
|
||||||
GstPlay *play = (GstPlay *) user_data;
|
GstPlay *play = (GstPlay *) user_data;
|
||||||
gchar key = '\0';
|
gchar key = '\0';
|
||||||
|
|
||||||
/* only want to switch/case on single char, not first char of string */
|
/* Switch on the first char for single char inputs,
|
||||||
if (key_input[0] != '\0' && key_input[1] == '\0')
|
* otherwise leave key = '\0' to fall through to
|
||||||
key = g_ascii_tolower (key_input[0]);
|
* the default case below */
|
||||||
|
if (key_input[0] != '\0' && key_input[1] == '\0') {
|
||||||
|
key = key_input[0];
|
||||||
|
}
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'k':
|
case 'k':
|
||||||
|
@ -1471,13 +1506,17 @@ keyboard_cb (const gchar * key_input, gpointer user_data)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'a':
|
case 'a':
|
||||||
play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_AUDIO);
|
case 'A':
|
||||||
|
play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_AUDIO, key == 'a');
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_VIDEO);
|
case 'V':
|
||||||
|
play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_VIDEO, key == 'v');
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_SUBTITLE);
|
case 'S':
|
||||||
|
play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_SUBTITLE,
|
||||||
|
key == 's');
|
||||||
break;
|
break;
|
||||||
case '0':
|
case '0':
|
||||||
play_do_seek (play, 0, play->rate, play->trick_mode);
|
play_do_seek (play, 0, play->rate, play->trick_mode);
|
||||||
|
|
Loading…
Reference in a new issue