filechooser: MCI video in a window of ours, and by extension
Tried under Wine: "put window at" left the video window of MCI where it was, at the top left of the dialog and at the size of the video. MCI now draws into a child window we make and move over the preview, with "window handle" and "put destination", which every version knows. Where DirectShow (the mpegvideo device) cannot open a file, the device MCI has for its extension takes it: waveaudio for WAV, the sequencer for MIDI. And as the type of a file on Windows is its extension, and not every system has a MIME type in the registry for .avi or .mp3, sound and video are also told by a short list of extensions.
This commit is contained in:
parent
8bf037a864
commit
fb2da8786c
1 changed files with 54 additions and 6 deletions
|
|
@ -11,7 +11,7 @@
|
|||
* - FFmpeg, as the programs ffmpeg (the pictures, through a pipe)
|
||||
* and ffplay (the sound).
|
||||
* - On Windows, the Media Control Interface every version since 3.1
|
||||
* has, which draws video into a window of its own over the preview.
|
||||
* has, which draws video into a window of ours over the preview.
|
||||
*
|
||||
* Nothing starts before the user asks; stopping stops it all.
|
||||
*
|
||||
|
|
@ -80,6 +80,7 @@ struct _GtkFileMedia
|
|||
|
||||
/* MCI */
|
||||
gchar *alias;
|
||||
gpointer video; /* HWND it draws into */
|
||||
gulong allocate_id;
|
||||
guint poll;
|
||||
};
|
||||
|
|
@ -1132,9 +1133,26 @@ mci_place (GtkWidget *area,
|
|||
x += (area->allocation.width - width) / 2;
|
||||
y += (area->allocation.height - height) / 2;
|
||||
|
||||
/* our own window over the preview, the video drawn into all of it */
|
||||
scale = gdk_window_get_scale_factor (toplevel->window);
|
||||
place = g_strdup_printf ("%d %d %d %d", x * scale, y * scale, width * scale, height * scale);
|
||||
mci_command (media, "put %s window at %s", place, NULL);
|
||||
if (media->video == NULL)
|
||||
{
|
||||
gchar *handle;
|
||||
|
||||
media->video = CreateWindowExW (0, L"STATIC", NULL, WS_CHILD | WS_CLIPSIBLINGS,
|
||||
0, 0, 1, 1,
|
||||
gdk_win32_drawable_get_handle (toplevel->window),
|
||||
NULL, GetModuleHandleW (NULL), NULL);
|
||||
if (media->video == NULL)
|
||||
return;
|
||||
handle = g_strdup_printf ("%lu", (gulong) (gsize) media->video);
|
||||
mci_command (media, "window %s handle %s", handle, NULL);
|
||||
g_free (handle);
|
||||
}
|
||||
SetWindowPos (media->video, HWND_TOP, x * scale, y * scale, width * scale, height * scale,
|
||||
SWP_SHOWWINDOW | SWP_NOACTIVATE);
|
||||
place = g_strdup_printf ("0 0 %d %d", width * scale, height * scale);
|
||||
mci_command (media, "put %s destination at %s", place, NULL);
|
||||
g_free (place);
|
||||
}
|
||||
|
||||
|
|
@ -1172,10 +1190,21 @@ mci_start (GtkFileMedia *media,
|
|||
}
|
||||
|
||||
media->alias = g_strdup_printf ("gtkpreview%u", ++serial);
|
||||
open = g_strdup_printf ("open \"%s\" type mpegvideo alias %%s parent %lu style child",
|
||||
path, (gulong) (gsize) gdk_win32_drawable_get_handle (toplevel->window));
|
||||
g_free (path);
|
||||
/* DirectShow first, which plays most; else the device MCI has for the
|
||||
* extension (waveaudio, sequencer for MIDI) */
|
||||
open = g_strdup_printf ("open \"%s\" type mpegvideo alias %%s", path);
|
||||
if (!mci_command (media, open, NULL, NULL))
|
||||
{
|
||||
g_free (open);
|
||||
open = g_strdup_printf ("open \"%s\" alias %%s", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free (open);
|
||||
open = NULL;
|
||||
}
|
||||
g_free (path);
|
||||
if (open && !mci_command (media, open, NULL, NULL))
|
||||
{
|
||||
g_free (open);
|
||||
g_free (media->alias);
|
||||
|
|
@ -1242,6 +1271,9 @@ mci_stop (GtkFileMedia *media)
|
|||
g_signal_handler_disconnect (media->area, media->allocate_id);
|
||||
if (media->alias)
|
||||
mci_command (media, "close %s", NULL, NULL);
|
||||
if (media->video)
|
||||
DestroyWindow (media->video);
|
||||
media->video = NULL;
|
||||
g_free (media->alias);
|
||||
media->alias = NULL;
|
||||
media->poll = 0;
|
||||
|
|
@ -1317,6 +1349,22 @@ _gtk_file_media_plays (GFileInfo *info)
|
|||
mime = g_content_type_get_mime_type (type);
|
||||
plays = mime && (g_str_has_prefix (mime, "audio/") || g_str_has_prefix (mime, "video/"));
|
||||
g_free (mime);
|
||||
#ifdef G_OS_WIN32
|
||||
/* the type is the extension there, and not every system has a MIME
|
||||
* type in the registry for it */
|
||||
if (!plays)
|
||||
{
|
||||
static const gchar * const extensions[] = {
|
||||
".avi", ".wmv", ".asf", ".mpg", ".mpeg", ".mp4", ".m4v", ".mov", ".mkv", ".webm",
|
||||
".mp3", ".wav", ".wma", ".mid", ".midi", ".aif", ".aiff", ".au", ".m4a", ".aac",
|
||||
".ogg", ".flac", NULL
|
||||
};
|
||||
gint i;
|
||||
|
||||
for (i = 0; extensions[i] && !plays; i++)
|
||||
plays = g_ascii_strcasecmp (type, extensions[i]) == 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return plays;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue