mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-09 08:55:33 +00:00
tools: play: add --shuffle command line option
This commit is contained in:
parent
60e87090eb
commit
0f8040862f
1 changed files with 27 additions and 1 deletions
|
@ -427,6 +427,24 @@ add_to_playlist (GPtrArray * playlist, const gchar * filename)
|
||||||
g_warning ("Could not make URI out of filename '%s'", filename);
|
g_warning ("Could not make URI out of filename '%s'", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
shuffle_uris (gchar ** uris, guint num)
|
||||||
|
{
|
||||||
|
gchar *tmp;
|
||||||
|
guint i, j;
|
||||||
|
|
||||||
|
if (num < 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < num; i++) {
|
||||||
|
/* gets equally distributed random number in 0..num-1 [0;num[ */
|
||||||
|
j = g_random_int_range (0, num);
|
||||||
|
tmp = uris[j];
|
||||||
|
uris[j] = uris[i];
|
||||||
|
uris[i] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -434,6 +452,7 @@ main (int argc, char **argv)
|
||||||
GPtrArray *playlist;
|
GPtrArray *playlist;
|
||||||
gboolean print_version = FALSE;
|
gboolean print_version = FALSE;
|
||||||
gboolean gapless = FALSE;
|
gboolean gapless = FALSE;
|
||||||
|
gboolean shuffle = FALSE;
|
||||||
gchar **filenames = NULL;
|
gchar **filenames = NULL;
|
||||||
gchar *audio_sink = NULL;
|
gchar *audio_sink = NULL;
|
||||||
gchar *video_sink = NULL;
|
gchar *video_sink = NULL;
|
||||||
|
@ -450,6 +469,8 @@ main (int argc, char **argv)
|
||||||
N_("Audio sink to use (default is autoaudiosink)"), NULL},
|
N_("Audio sink to use (default is autoaudiosink)"), NULL},
|
||||||
{"gapless", 0, 0, G_OPTION_ARG_NONE, &gapless,
|
{"gapless", 0, 0, G_OPTION_ARG_NONE, &gapless,
|
||||||
N_("Enable gapless playback"), NULL},
|
N_("Enable gapless playback"), NULL},
|
||||||
|
{"shuffle", 0, 0, G_OPTION_ARG_NONE, &shuffle,
|
||||||
|
N_("Shuffle playlist"), NULL},
|
||||||
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL},
|
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
@ -503,10 +524,15 @@ main (int argc, char **argv)
|
||||||
}
|
}
|
||||||
g_strfreev (filenames);
|
g_strfreev (filenames);
|
||||||
|
|
||||||
|
num = playlist->len;
|
||||||
g_ptr_array_add (playlist, NULL);
|
g_ptr_array_add (playlist, NULL);
|
||||||
|
|
||||||
/* play */
|
|
||||||
uris = (gchar **) g_ptr_array_free (playlist, FALSE);
|
uris = (gchar **) g_ptr_array_free (playlist, FALSE);
|
||||||
|
|
||||||
|
if (shuffle)
|
||||||
|
shuffle_uris (uris, num);
|
||||||
|
|
||||||
|
/* play */
|
||||||
play = play_new (uris, audio_sink, video_sink, gapless);
|
play = play_new (uris, audio_sink, video_sink, gapless);
|
||||||
|
|
||||||
do_play (play);
|
do_play (play);
|
||||||
|
|
Loading…
Reference in a new issue