static void keyboard_cb (const gchar * key_input, gpointer user_data) { GstPlay *play = (GstPlay *) user_data; switch (g_ascii_tolower (key_input[0])) { case 'i': { GstPlayerMediaInfo *media_info = gst_player_get_media_info (play->player); if (media_info) { print_media_info (media_info); g_object_unref (media_info); print_current_tracks (play); } break; } case ' ': toggle_paused (play); break; case 'q': case 'Q': g_main_loop_quit (play->loop); break; case '>': if (!play_next (play)) { g_print ("\nReached end of play list.\n"); g_main_loop_quit (play->loop); } break; case '<': play_prev (play); break; case 27: /* ESC */ if (key_input[1] == '\0') { g_main_loop_quit (play->loop); break; } /* fall through */ default: if (strcmp (key_input, GST_PLAY_KB_ARROW_RIGHT) == 0) { relative_seek (play, +0.08); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) { relative_seek (play, -0.01); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_UP) == 0) { play_set_relative_volume (play, +1.0 / VOLUME_STEPS); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_DOWN) == 0) { play_set_relative_volume (play, -1.0 / VOLUME_STEPS); } else { GST_INFO ("keyboard input:"); for (; *key_input != '\0'; ++key_input) GST_INFO (" code %3d", *key_input); } break; } }
static GstPlay * play_new (gchar ** uris, gdouble initial_volume) { GstPlay *play; play = g_new0 (GstPlay, 1); play->uris = uris; play->num_uris = g_strv_length (uris); play->cur_idx = -1; play->player = gst_player_new (); g_object_set (play->player, "dispatch-to-main-context", TRUE, NULL); g_signal_connect (play->player, "position-updated", G_CALLBACK (position_updated_cb), play); g_signal_connect (play->player, "end-of-stream", G_CALLBACK (end_of_stream_cb), play); g_signal_connect (play->player, "error", G_CALLBACK (error_cb), play); play->loop = g_main_loop_new (NULL, FALSE); play->desired_state = GST_STATE_PLAYING; play_set_relative_volume (play, initial_volume - 1.0); return play; }
static GstPlay * play_new (gchar ** uris, gdouble initial_volume) { GstPlay *play; play = g_new0 (GstPlay, 1); play->uris = uris; play->num_uris = g_strv_length (uris); play->cur_idx = -1; play->player = gst_player_new_full (NULL, gst_player_g_main_context_signal_dispatcher_new (NULL)); g_signal_connect (play->player, "position-updated", G_CALLBACK (position_updated_cb), play); g_signal_connect (play->player, "state-changed", G_CALLBACK (state_changed_cb), play); g_signal_connect (play->player, "buffering", G_CALLBACK (buffering_cb), play); g_signal_connect (play->player, "end-of-stream", G_CALLBACK (end_of_stream_cb), play); g_signal_connect (play->player, "error", G_CALLBACK (error_cb), play); g_signal_connect (play->player, "media-info-updated", G_CALLBACK (media_info_cb), play); play->loop = g_main_loop_new (NULL, FALSE); play->desired_state = GST_STATE_PLAYING; play_set_relative_volume (play, initial_volume - 1.0); return play; }
static GstPlay * play_new (gchar ** uris, const gchar * audio_sink, const gchar * video_sink, gboolean gapless, gdouble initial_volume, gboolean verbose, const gchar * flags_string) { GstElement *sink, *playbin; GstPlay *play; playbin = gst_element_factory_make ("playbin", "playbin"); if (playbin == NULL) return NULL; play = g_new0 (GstPlay, 1); play->uris = uris; play->num_uris = g_strv_length (uris); play->cur_idx = -1; play->playbin = playbin; if (audio_sink != NULL) { if (strchr (audio_sink, ' ') != NULL) sink = gst_parse_bin_from_description (audio_sink, TRUE, NULL); else sink = gst_element_factory_make (audio_sink, NULL); if (sink != NULL) g_object_set (play->playbin, "audio-sink", sink, NULL); else g_warning ("Couldn't create specified audio sink '%s'", audio_sink); } if (video_sink != NULL) { if (strchr (video_sink, ' ') != NULL) sink = gst_parse_bin_from_description (video_sink, TRUE, NULL); else sink = gst_element_factory_make (video_sink, NULL); if (sink != NULL) g_object_set (play->playbin, "video-sink", sink, NULL); else g_warning ("Couldn't create specified video sink '%s'", video_sink); } if (flags_string != NULL) { GParamSpec *pspec; GValue val = { 0, }; pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (playbin), "flags"); g_value_init (&val, pspec->value_type); if (gst_value_deserialize (&val, flags_string)) g_object_set_property (G_OBJECT (play->playbin), "flags", &val); else g_printerr ("Couldn't convert '%s' to playbin flags!\n", flags_string); g_value_unset (&val); } if (verbose) { play->deep_notify_id = g_signal_connect (play->playbin, "deep-notify", G_CALLBACK (gst_object_default_deep_notify), NULL); } play->loop = g_main_loop_new (NULL, FALSE); play->bus_watch = gst_bus_add_watch (GST_ELEMENT_BUS (play->playbin), play_bus_msg, play); /* FIXME: make configurable incl. 0 for disable */ play->timeout = g_timeout_add (100, play_timeout, play); play->missing = NULL; play->buffering = FALSE; play->is_live = FALSE; play->desired_state = GST_STATE_PLAYING; play->gapless = gapless; if (gapless) { g_signal_connect (play->playbin, "about-to-finish", G_CALLBACK (play_about_to_finish), play); } if (initial_volume != -1) play_set_relative_volume (play, initial_volume - 1.0); play->rate = 1.0; play->trick_mode = GST_PLAY_TRICK_MODE_NONE; return play; }
static void keyboard_cb (const gchar * key_input, gpointer user_data) { GstPlay *play = (GstPlay *) user_data; gchar key = '\0'; /* only want to switch/case on single char, not first char of string */ if (key_input[0] != '\0' && key_input[1] == '\0') key = g_ascii_tolower (key_input[0]); switch (key) { case 'k': print_keyboard_help (); break; case ' ': toggle_paused (play); break; case 'q': case 'Q': g_main_loop_quit (play->loop); break; case 'n': case '>': if (!play_next (play)) { g_print ("\n%s\n", _("Reached end of play list.")); g_main_loop_quit (play->loop); } break; case 'b': case '<': play_prev (play); break; case '+': if (play->rate > -0.2 && play->rate < 0.0) play_set_relative_playback_rate (play, 0.0, TRUE); else if (ABS (play->rate) < 2.0) play_set_relative_playback_rate (play, 0.1, FALSE); else if (ABS (play->rate) < 4.0) play_set_relative_playback_rate (play, 0.5, FALSE); else play_set_relative_playback_rate (play, 1.0, FALSE); break; case '-': if (play->rate > 0.0 && play->rate < 0.20) play_set_relative_playback_rate (play, 0.0, TRUE); else if (ABS (play->rate) <= 2.0) play_set_relative_playback_rate (play, -0.1, FALSE); else if (ABS (play->rate) <= 4.0) play_set_relative_playback_rate (play, -0.5, FALSE); else play_set_relative_playback_rate (play, -1.0, FALSE); break; case 'd': play_set_relative_playback_rate (play, 0.0, TRUE); break; case 't': play_switch_trick_mode (play); break; case 27: /* ESC */ if (key_input[1] == '\0') { g_main_loop_quit (play->loop); break; } case 'a': play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_AUDIO); break; case 'v': play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_VIDEO); break; case 's': play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_SUBTITLE); break; case '0': play_do_seek (play, 0, play->rate, play->trick_mode); break; default: if (strcmp (key_input, GST_PLAY_KB_ARROW_RIGHT) == 0) { relative_seek (play, +0.08); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) { relative_seek (play, -0.01); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_UP) == 0) { play_set_relative_volume (play, +1.0 / VOLUME_STEPS); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_DOWN) == 0) { play_set_relative_volume (play, -1.0 / VOLUME_STEPS); } else { GST_INFO ("keyboard input:"); for (; *key_input != '\0'; ++key_input) GST_INFO (" code %3d", *key_input); } break; } }
static GstPlay * play_new (gchar ** uris, const gchar * audio_sink, const gchar * video_sink, gboolean gapless, gdouble initial_volume) { GstElement *sink; GstPlay *play; play = g_new0 (GstPlay, 1); play->uris = uris; play->num_uris = g_strv_length (uris); play->cur_idx = -1; play->playbin = gst_element_factory_make ("playbin", "playbin"); if (audio_sink != NULL) { if (strchr (audio_sink, ' ') != NULL) sink = gst_parse_bin_from_description (audio_sink, TRUE, NULL); else sink = gst_element_factory_make (audio_sink, NULL); if (sink != NULL) g_object_set (play->playbin, "audio-sink", sink, NULL); else g_warning ("Couldn't create specified audio sink '%s'", audio_sink); } if (video_sink != NULL) { if (strchr (video_sink, ' ') != NULL) sink = gst_parse_bin_from_description (video_sink, TRUE, NULL); else sink = gst_element_factory_make (video_sink, NULL); if (sink != NULL) g_object_set (play->playbin, "video-sink", sink, NULL); else g_warning ("Couldn't create specified video sink '%s'", video_sink); } play->loop = g_main_loop_new (NULL, FALSE); play->bus_watch = gst_bus_add_watch (GST_ELEMENT_BUS (play->playbin), play_bus_msg, play); /* FIXME: make configurable incl. 0 for disable */ play->timeout = g_timeout_add (100, play_timeout, play); play->missing = NULL; play->buffering = FALSE; play->is_live = FALSE; play->desired_state = GST_STATE_PLAYING; play->gapless = gapless; if (gapless) { g_signal_connect (play->playbin, "about-to-finish", G_CALLBACK (play_about_to_finish), play); } play_set_relative_volume (play, initial_volume - 1.0); return play; }