1 /* compile: cc win_player.c -o win_player.exe -L<path/libvlc> -lvlc */
8 #define SCREEN_WIDTH 1500
9 #define SCREEN_HEIGHT 900
13 libvlc_instance_t
*p_libvlc
;
14 libvlc_media_player_t
*p_mediaplayer
;
18 static const char *AspectRatio
= NULL
;
20 static LRESULT CALLBACK
WindowProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
22 if( message
== WM_CREATE
)
24 /* Store p_mediaplayer for future use */
25 CREATESTRUCT
*c
= (CREATESTRUCT
*)lParam
;
26 SetWindowLongPtr( hWnd
, GWLP_USERDATA
, (LONG_PTR
)c
->lpCreateParams
);
30 LONG_PTR p_user_data
= GetWindowLongPtr( hWnd
, GWLP_USERDATA
);
31 if( p_user_data
== 0 )
32 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
33 struct vlc_context
*ctx
= (struct vlc_context
*)p_user_data
;
42 HDROP hDrop
= (HDROP
)wParam
;
43 char file_path
[MAX_PATH
];
44 libvlc_media_player_stop_async( ctx
->p_mediaplayer
);
46 if (DragQueryFile(hDrop
, 0, file_path
, sizeof(file_path
)))
48 libvlc_media_t
*p_media
= libvlc_media_new_path( ctx
->p_libvlc
, file_path
);
49 libvlc_media_t
*p_old_media
= libvlc_media_player_get_media( ctx
->p_mediaplayer
);
50 libvlc_media_player_set_media( ctx
->p_mediaplayer
, p_media
);
51 libvlc_media_release( p_old_media
);
53 libvlc_media_player_play( ctx
->p_mediaplayer
);
61 int key
= tolower( (unsigned char)MapVirtualKey( wParam
, 2 ) );
64 if (AspectRatio
== NULL
)
65 AspectRatio
= "16:10";
66 else if (strcmp(AspectRatio
,"16:10")==0)
68 else if (strcmp(AspectRatio
,"16:9")==0)
70 else if (strcmp(AspectRatio
,"4:3")==0)
71 AspectRatio
= "185:100";
72 else if (strcmp(AspectRatio
,"185:100")==0)
73 AspectRatio
= "221:100";
74 else if (strcmp(AspectRatio
,"221:100")==0)
75 AspectRatio
= "235:100";
76 else if (strcmp(AspectRatio
,"235:100")==0)
77 AspectRatio
= "239:100";
78 else if (strcmp(AspectRatio
,"239:100")==0)
80 else if (strcmp(AspectRatio
,"5:3")==0)
82 else if (strcmp(AspectRatio
,"5:4")==0)
84 else if (strcmp(AspectRatio
,"1:1")==0)
86 libvlc_video_set_aspect_ratio( ctx
->p_mediaplayer
, AspectRatio
);
93 return DefWindowProc (hWnd
, message
, wParam
, lParam
);
96 int WINAPI
WinMain(HINSTANCE hInstance
,
97 HINSTANCE hPrevInstance
,
103 struct vlc_context Context
;
104 libvlc_media_t
*p_media
;
108 /* remove "" around the given path */
109 if (lpCmdLine
[0] == '"')
111 file_path
= strdup( lpCmdLine
+1 );
112 if (file_path
[strlen(file_path
)-1] == '"')
113 file_path
[strlen(file_path
)-1] = '\0';
116 file_path
= strdup( lpCmdLine
);
118 Context
.p_libvlc
= libvlc_new( 0, NULL
);
119 p_media
= libvlc_media_new_path( Context
.p_libvlc
, file_path
);
121 Context
.p_mediaplayer
= libvlc_media_player_new_from_media( p_media
);
123 ZeroMemory(&wc
, sizeof(WNDCLASSEX
));
125 wc
.cbSize
= sizeof(WNDCLASSEX
);
126 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
127 wc
.lpfnWndProc
= WindowProc
;
128 wc
.hInstance
= hInstance
;
129 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
130 wc
.lpszClassName
= "WindowClass";
132 RegisterClassEx(&wc
);
134 RECT wr
= {0, 0, SCREEN_WIDTH
, SCREEN_HEIGHT
};
135 AdjustWindowRect(&wr
, WS_OVERLAPPEDWINDOW
, FALSE
);
137 hWnd
= CreateWindowEx(0,
141 CW_USEDEFAULT
, CW_USEDEFAULT
,
148 DragAcceptFiles(hWnd
, TRUE
);
150 libvlc_media_player_set_hwnd(Context
.p_mediaplayer
, hWnd
);
152 ShowWindow(hWnd
, nCmdShow
);
154 libvlc_media_player_play( Context
.p_mediaplayer
);
157 while (GetMessage(&msg
, NULL
, 0, 0))
159 TranslateMessage(&msg
);
160 DispatchMessage(&msg
);
162 if(msg
.message
== WM_QUIT
)
166 libvlc_media_player_stop_async( Context
.p_mediaplayer
);
168 libvlc_media_release( libvlc_media_player_get_media( Context
.p_mediaplayer
) );
169 libvlc_media_player_release( Context
.p_mediaplayer
);
170 libvlc_release( Context
.p_libvlc
);