videotoolbox: rework >= 10bit output handling
[vlc.git] / doc / libvlc / win_player.c
blob4c1e84a37587c6254f4d36f9c109b6b3d32743fa
1 /* compile: cc win_player.c -o win_player.exe -L<path/libvlc> -lvlc */
3 #include <windows.h>
4 #include <assert.h>
6 #include <vlc/vlc.h>
8 #define SCREEN_WIDTH 1500
9 #define SCREEN_HEIGHT 900
11 struct vlc_context
13 libvlc_instance_t *p_libvlc;
14 libvlc_media_player_t *p_mediaplayer;
18 static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
20 if( message == WM_CREATE )
22 /* Store p_mediaplayer for future use */
23 CREATESTRUCT *c = (CREATESTRUCT *)lParam;
24 SetWindowLongPtr( hWnd, GWLP_USERDATA, (LONG_PTR)c->lpCreateParams );
25 return 0;
28 LONG_PTR p_user_data = GetWindowLongPtr( hWnd, GWLP_USERDATA );
29 if( p_user_data == 0 )
30 return DefWindowProc(hWnd, message, wParam, lParam);
31 struct vlc_context *ctx = (struct vlc_context *)p_user_data;
33 switch(message)
35 case WM_DESTROY:
36 PostQuitMessage(0);
37 return 0;
38 case WM_DROPFILES:
40 HDROP hDrop = (HDROP)wParam;
41 char file_path[MAX_PATH];
42 libvlc_media_player_stop_async( ctx->p_mediaplayer );
44 if (DragQueryFile(hDrop, 0, file_path, sizeof(file_path)))
46 libvlc_media_t *p_media = libvlc_media_new_path( ctx->p_libvlc, file_path );
47 libvlc_media_t *p_old_media = libvlc_media_player_get_media( ctx->p_mediaplayer );
48 libvlc_media_player_set_media( ctx->p_mediaplayer, p_media );
49 libvlc_media_release( p_old_media );
51 libvlc_media_player_play( ctx->p_mediaplayer );
53 DragFinish(hDrop);
55 return 0;
58 return DefWindowProc (hWnd, message, wParam, lParam);
61 int WINAPI WinMain(HINSTANCE hInstance,
62 HINSTANCE hPrevInstance,
63 LPSTR lpCmdLine,
64 int nCmdShow)
66 WNDCLASSEX wc;
67 char *file_path;
68 struct vlc_context Context;
69 libvlc_media_t *p_media;
70 (void)hPrevInstance;
71 HWND hWnd;
73 /* remove "" around the given path */
74 if (lpCmdLine[0] == '"')
76 file_path = strdup( lpCmdLine+1 );
77 if (file_path[strlen(file_path)-1] == '"')
78 file_path[strlen(file_path)-1] = '\0';
80 else
81 file_path = strdup( lpCmdLine );
83 Context.p_libvlc = libvlc_new( 0, NULL );
84 p_media = libvlc_media_new_path( Context.p_libvlc, file_path );
85 free( file_path );
86 Context.p_mediaplayer = libvlc_media_player_new_from_media( p_media );
88 ZeroMemory(&wc, sizeof(WNDCLASSEX));
90 wc.cbSize = sizeof(WNDCLASSEX);
91 wc.style = CS_HREDRAW | CS_VREDRAW;
92 wc.lpfnWndProc = WindowProc;
93 wc.hInstance = hInstance;
94 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
95 wc.lpszClassName = "WindowClass";
97 RegisterClassEx(&wc);
99 RECT wr = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
100 AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
102 hWnd = CreateWindowEx(0,
103 "WindowClass",
104 "libvlc Demo app",
105 WS_OVERLAPPEDWINDOW,
106 CW_USEDEFAULT, CW_USEDEFAULT,
107 wr.right - wr.left,
108 wr.bottom - wr.top,
109 NULL,
110 NULL,
111 hInstance,
112 &Context);
113 DragAcceptFiles(hWnd, TRUE);
115 libvlc_media_player_set_hwnd(Context.p_mediaplayer, hWnd);
117 ShowWindow(hWnd, nCmdShow);
119 libvlc_media_player_play( Context.p_mediaplayer );
121 MSG msg;
122 while (GetMessage(&msg, NULL, 0, 0))
124 TranslateMessage(&msg);
125 DispatchMessage(&msg);
127 if(msg.message == WM_QUIT)
128 break;
131 libvlc_media_player_stop_async( Context.p_mediaplayer );
133 libvlc_media_release( libvlc_media_player_get_media( Context.p_mediaplayer ) );
134 libvlc_media_player_release( Context.p_mediaplayer );
135 libvlc_release( Context.p_libvlc );
137 return msg.wParam;