[MPlayer-dev-eng] Seek in a movie by mouse click
Milan Ilavsky
ilavsky.milan at gmail.com
Mon Sep 24 19:16:56 CEST 2007
Compn <tempn <at> twmi.rr.com> writes:
> to seek using mouse you could modify input.conf
> MOUSE_BTN0 seek +60
> MOUSE_BTN1 seek -60
> also i think mousewheel can seek too.
Yes, i know that and mousewheel works nice.
But that patch works a bit differently. This one seek to the concrete position
in the movie by click to the concrete (width) position in the bottom of
window/screen. In other words, seek is dependent on mouse cursor position in the
time of click.
> i cant test as i dont have x11 stuff.
Btw, thank you. I forgot that case, where the code is compiled without X11
compilation with this patch will break. I have fixed it and now I'm sending this
a fixed patch.
Milan Ilavsky
Index: input/input.c
===================================================================
--- input/input.c (revision 24596)
+++ input/input.c (working copy)
@@ -39,6 +39,10 @@
#include "ar.h"
+#ifdef HAVE_X11
+#include <libvo/video_out.h>
+#endif
+
/// This array defines all known commands.
/// The first field is an id used to recognize the command without too many strcmp.
/// The second is obviously the command name.
@@ -1060,6 +1064,18 @@
num_key_down++;
last_key_down = GetTimer();
ar_state = 0;
+#ifdef HAVE_X11
+ // seek on mouse click
+ if (mouseseek && code == MOUSE_BTN0 && (vo_dheight-mouse_pos_y) < 50) {
// if mouse is on bottom
and click on mouse button
+ char str_cmd[20];
+ if (vo_fs) seek_mouse_pos =
(float)((float)(mouse_pos_x)/(float)vo_screenwidth);
// calculate seek position
+ else seek_mouse_pos = (float)((float)(mouse_pos_x)/(float)vo_dwidth);
+ sprintf(str_cmd, "seek %.4f 1", seek_mouse_pos*100.0f);
// generate command
+ ret = mp_input_parse_cmd(str_cmd);
+ if(ret)
+ return ret;
+ }
+#endif
return NULL;
}
// key released
Index: libvo/x11_common.c
===================================================================
--- libvo/x11_common.c (revision 24596)
+++ libvo/x11_common.c (working copy)
@@ -74,6 +74,13 @@
static int timeout_save = 0;
static int kdescreensaver_was_running = 0;
+// seek on mouse click
+int mouseseek = 1;
+int mouse_pos_x = 0;
+int mouse_pos_y = 0;
+int visible_cursor = 1;
+float seek_mouse_pos = 0.0f;
+
char *mDisplayName = NULL;
Display *mDisplay = NULL;
Window mRootWin;
@@ -184,6 +191,7 @@
if (bm_no != None)
XFreePixmap(disp, bm_no);
XFreeColors(disp,colormap,&black.pixel,1,0);
+ visible_cursor = 0; // set mouse visibility
status
}
void vo_showcursor(Display * disp, Window win)
@@ -191,6 +199,7 @@
if (WinID == 0)
return;
XDefineCursor(disp, win, 0);
+ visible_cursor = 1; // set mouse visibility
status
}
static int x11_errorhandler(Display * display, XErrorEvent * event)
@@ -1090,7 +1099,9 @@
ret |= VO_EVENT_KEYPRESS;
}
break;
- case MotionNotify:
+ case MotionNotify:
+ mouse_pos_x = Event.xmotion.x;
+ mouse_pos_y = Event.xmotion.y;
if(enable_mouse_movements)
{
char cmd_str[40];
Index: libvo/video_out.h
===================================================================
--- libvo/video_out.h (revision 24596)
+++ libvo/video_out.h (working copy)
@@ -194,6 +194,15 @@
extern int xinerama_x;
extern int xinerama_y;
+#ifdef HAVE_X11
+// seek on mouse click
+extern int mouseseek;
+extern int mouse_pos_x;
+extern int mouse_pos_y;
+extern int visible_cursor;
+extern float seek_mouse_pos;
+#endif
+
// correct resolution/bpp on screen: (should be autodetected by vo_init())
extern int vo_depthonscreen;
extern int vo_screenwidth;
Index: libvo/vo_xv.c
===================================================================
--- libvo/vo_xv.c (revision 24596)
+++ libvo/vo_xv.c (working copy)
@@ -464,7 +464,11 @@
}
static inline void put_xvimage( XvImage * xvi )
-{
+{
+ // seek on mouse click
+ static int bol = 0;
+ int ww, hh;
+
#ifdef HAVE_SHM
if (Shmem_Flag)
{
@@ -483,6 +487,23 @@
vo_dwidth + vo_panscan_x,
vo_dheight + vo_panscan_y);
}
+ // seek on mouse click
+ if (mouseseek) {
+ hh = (vo_fs)?vo_screenheight:vo_dheight;
+ ww = (vo_fs)?vo_screenwidth:vo_dwidth;
+ if (hh-mouse_pos_y < 20 && visible_cursor) { //
show progress bar on bottom, if mouse is on bottom and is visible
+ bol = 1;
+ XSetForeground( mDisplay, vo_gc, 0x333333);
+ XFillRectangle( mDisplay, vo_window, vo_gc, 2, hh-12, ww-4, 5);
+
+ XSetForeground( mDisplay, vo_gc, 0xFF0000);
+ XFillRectangle( mDisplay, vo_window, vo_gc, 2, hh-12, (ww-4)*seek_mouse_pos,
5);
+ } else if (bol){ // if
mouse leave progress bar, clear bar
+ bol = 0;
+ XSetForeground( mDisplay, vo_gc, 0x0);
+ XFillRectangle( mDisplay, vo_window, vo_gc, 2, hh-12, ww-4, 5);
+ }
+ }
}
static void check_events(void)
Index: mplayer.c
===================================================================
--- mplayer.c (revision 24596)
+++ mplayer.c (working copy)
@@ -3404,7 +3404,13 @@
time_frame += frame_time / playback_speed; // for nosound
}
}
-
+#ifdef HAVE_X11
+ // seek on mouse click
+ if (mouseseek && mpctx->demuxer->video->sh) {
+ sh_video_t *sh_video = mpctx->demuxer->video->sh;
+ seek_mouse_pos =
(float)sh_video->pts/demuxer_get_time_length(mpctx->demuxer); // set video
position
+ }
+#endif
// ==========================================================================
// current_module="draw_osd";
Index: cfg-mplayer.h
===================================================================
--- cfg-mplayer.h (revision 24596)
+++ cfg-mplayer.h (working copy)
@@ -37,6 +37,7 @@
#ifdef HAVE_X11
extern int fs_layer;
extern int stop_xscreensaver;
+extern int mouseseek;
#endif
#ifdef HAVE_MENU
@@ -178,6 +179,11 @@
#endif
#endif
+#ifdef HAVE_X11
+ // seek on mouse click
+ {"mouseseek", &mouseseek, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+ {"nomouseseek", &mouseseek, CONF_TYPE_FLAG, 0, 1, 0, NULL},
+#endif
// force window width/height or resolution (with -vm)
{"x", &opt_screen_size_x, CONF_TYPE_INT, CONF_RANGE, 0, 4096, NULL},
{"y", &opt_screen_size_y, CONF_TYPE_INT, CONF_RANGE, 0, 4096, NULL},
More information about the MPlayer-dev-eng
mailing list