MediaPlayer.cs 122 KB
Newer Older
Martin Finkel's avatar
Martin Finkel committed
1 2 3
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
4
using LibVLCSharp.Shared.Helpers;
5
using LibVLCSharp.Shared.Structures;
Martin Finkel's avatar
Martin Finkel committed
6

7
namespace LibVLCSharp.Shared
Martin Finkel's avatar
Martin Finkel committed
8
{
9 10 11
    /// <summary>
    /// The MediaPlayer type is used to control playback, set renderers, provide events and much more
    /// </summary>
Martin Finkel's avatar
Martin Finkel committed
12 13
    public class MediaPlayer : Internal
    {
14
        readonly struct Native
Martin Finkel's avatar
Martin Finkel committed
15
        {
16

17
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
18
                EntryPoint = "libvlc_media_player_new")]
Martin Finkel's avatar
Martin Finkel committed
19
            internal static extern IntPtr LibVLCMediaPlayerNew(IntPtr libvlc);
Martin Finkel's avatar
Martin Finkel committed
20

21

22
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
23 24 25
                EntryPoint = "libvlc_media_player_release")]
            internal static extern void LibVLCMediaPlayerRelease(IntPtr mediaPlayer);

26

27
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
28 29 30
                EntryPoint = "libvlc_media_player_new_from_media")]
            internal static extern IntPtr LibVLCMediaPlayerNewFromMedia(IntPtr media);

31

32
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
33 34 35
                EntryPoint = "libvlc_media_player_set_media")]
            internal static extern void LibVLCMediaPlayerSetMedia(IntPtr mediaPlayer, IntPtr media);

36

37
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
38 39 40
                EntryPoint = "libvlc_media_player_get_media")]
            internal static extern IntPtr LibVLCMediaPlayerGetMedia(IntPtr mediaPlayer);

41

42
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
43 44
                EntryPoint = "libvlc_media_player_event_manager")]
            internal static extern IntPtr LibVLCMediaPlayerEventManager(IntPtr mediaPlayer);
Martin Finkel's avatar
Martin Finkel committed
45

46

47
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
48 49 50
                EntryPoint = "libvlc_media_player_is_playing")]
            internal static extern int LibVLCMediaPlayerIsPlaying(IntPtr mediaPlayer);

51

52
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
53 54 55
                EntryPoint = "libvlc_media_player_play")]
            internal static extern int LibVLCMediaPlayerPlay(IntPtr mediaPlayer);

56

57
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
58 59 60
                EntryPoint = "libvlc_media_player_set_pause")]
            internal static extern void LibVLCMediaPlayerSetPause(IntPtr mediaPlayer, bool pause);

61

62
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
63 64 65
                EntryPoint = "libvlc_media_player_pause")]
            internal static extern void LibVLCMediaPlayerPause(IntPtr mediaPlayer);

66
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
67 68
                EntryPoint = "libvlc_media_player_stop")]
            internal static extern void LibVLCMediaPlayerStop(IntPtr mediaPlayer);
69

70
#if APPLE || NETFRAMEWORK || NETSTANDARD
71
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
72 73 74
                EntryPoint = "libvlc_media_player_set_nsobject")]
            internal static extern void LibVLCMediaPlayerSetNsobject(IntPtr mediaPlayer, IntPtr drawable);

75
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
76 77
                EntryPoint = "libvlc_media_player_get_nsobject")]
            internal static extern IntPtr LibVLCMediaPlayerGetNsobject(IntPtr mediaPlayer);
Martin Finkel's avatar
Martin Finkel committed
78
#endif
79
#if NETFRAMEWORK || NETSTANDARD
80
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
81 82 83
                EntryPoint = "libvlc_media_player_set_xwindow")]
            internal static extern void LibVLCMediaPlayerSetXwindow(IntPtr mediaPlayer, uint drawable);

84
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
85 86
                EntryPoint = "libvlc_media_player_get_xwindow")]
            internal static extern uint LibVLCMediaPlayerGetXwindow(IntPtr mediaPlayer);
87

88
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
89 90 91
                EntryPoint = "libvlc_media_player_set_hwnd")]
            internal static extern void LibVLCMediaPlayerSetHwnd(IntPtr mediaPlayer, IntPtr drawable);

92
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
93 94
                EntryPoint = "libvlc_media_player_get_hwnd")]
            internal static extern IntPtr LibVLCMediaPlayerGetHwnd(IntPtr mediaPlayer);
95
#endif
96
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
97 98 99
                EntryPoint = "libvlc_media_player_get_length")]
            internal static extern long LibVLCMediaPlayerGetLength(IntPtr mediaPlayer);

100
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
101 102 103
                EntryPoint = "libvlc_media_player_get_time")]
            internal static extern long LibVLCMediaPlayerGetTime(IntPtr mediaPlayer);

104

105
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
106 107 108
                EntryPoint = "libvlc_media_player_set_time")]
            internal static extern void LibVLCMediaPlayerSetTime(IntPtr mediaPlayer, long time);

109

110
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
111 112 113
                EntryPoint = "libvlc_media_player_get_position")]
            internal static extern float LibVLCMediaPlayerGetPosition(IntPtr mediaPlayer);

114

115
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
116 117 118
                EntryPoint = "libvlc_media_player_set_position")]
            internal static extern void LibVLCMediaPlayerSetPosition(IntPtr mediaPlayer, float position);

119

120
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
121 122 123
                EntryPoint = "libvlc_media_player_set_chapter")]
            internal static extern void LibVLCMediaPlayerSetChapter(IntPtr mediaPlayer, int chapter);

124

125
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
126 127 128
                EntryPoint = "libvlc_media_player_get_chapter")]
            internal static extern int LibVLCMediaPlayerGetChapter(IntPtr mediaPlayer);

129

130
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
131 132
                EntryPoint = "libvlc_media_player_get_chapter_count")]
            internal static extern int LibVLCMediaPlayerGetChapterCount(IntPtr mediaPlayer);
Martin Finkel's avatar
Martin Finkel committed
133

134

135
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
136 137 138
                EntryPoint = "libvlc_media_player_will_play")]
            internal static extern int LibVLCMediaPlayerWillPlay(IntPtr mediaPlayer);

139

140
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
141 142 143
                EntryPoint = "libvlc_media_player_get_chapter_count_for_title")]
            internal static extern int LibVLCMediaPlayerGetChapterCountForTitle(IntPtr mediaPlayer, int title);

144

145
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
146 147 148
                EntryPoint = "libvlc_media_player_set_title")]
            internal static extern void LibVLCMediaPlayerSetTitle(IntPtr mediaPlayer, int title);

149

150
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
151 152 153
                EntryPoint = "libvlc_media_player_get_title")]
            internal static extern int LibVLCMediaPlayerGetTitle(IntPtr mediaPlayer);

154

155
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
156 157 158
                EntryPoint = "libvlc_media_player_get_title_count")]
            internal static extern int LibVLCMediaPlayerGetTitleCount(IntPtr mediaPlayer);

159

160
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
161 162 163
                EntryPoint = "libvlc_media_player_previous_chapter")]
            internal static extern void LibVLCMediaPlayerPreviousChapter(IntPtr mediaPlayer);

164

165
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
166 167 168
                EntryPoint = "libvlc_media_player_next_chapter")]
            internal static extern void LibVLCMediaPlayerNextChapter(IntPtr mediaPlayer);

169

170
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
171 172 173
                EntryPoint = "libvlc_media_player_get_rate")]
            internal static extern float LibVLCMediaPlayerGetRate(IntPtr mediaPlayer);

174

175
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
176 177 178
                EntryPoint = "libvlc_media_player_set_rate")]
            internal static extern int LibVLCMediaPlayerSetRate(IntPtr mediaPlayer, float rate);

179

180
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
181 182 183
                EntryPoint = "libvlc_media_player_get_state")]
            internal static extern VLCState LibVLCMediaPlayerGetState(IntPtr mediaPlayer);

184

185
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
186 187 188
                EntryPoint = "libvlc_media_player_get_fps")]
            internal static extern float LibVLCMediaPlayerGetFps(IntPtr mediaPlayer);

189

190
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
191 192 193
                EntryPoint = "libvlc_media_player_has_vout")]
            internal static extern uint LibVLCMediaPlayerHasVout(IntPtr mediaPlayer);

194

195
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
196 197 198
                EntryPoint = "libvlc_media_player_is_seekable")]
            internal static extern int LibVLCMediaPlayerIsSeekable(IntPtr mediaPlayer);

199

200
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
201 202 203
                EntryPoint = "libvlc_media_player_can_pause")]
            internal static extern int LibVLCMediaPlayerCanPause(IntPtr mediaPlayer);

204

205
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
206 207 208
                EntryPoint = "libvlc_media_player_program_scrambled")]
            internal static extern int LibVLCMediaPlayerProgramScrambled(IntPtr mediaPlayer);

209

210
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
211 212 213
                EntryPoint = "libvlc_media_player_next_frame")]
            internal static extern void LibVLCMediaPlayerNextFrame(IntPtr mediaPlayer);

214

215
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
216 217 218
                EntryPoint = "libvlc_media_player_navigate")]
            internal static extern void LibVLCMediaPlayerNavigate(IntPtr mediaPlayer, uint navigate);

219

220
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
221 222 223
                EntryPoint = "libvlc_media_player_set_video_title_display")]
            internal static extern void LibVLCMediaPlayerSetVideoTitleDisplay(IntPtr mediaPlayer, Position position, uint timeout);

224

225
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
226 227
                EntryPoint = "libvlc_toggle_fullscreen")]
            internal static extern void LibVLCToggleFullscreen(IntPtr mediaPlayer);
Martin Finkel's avatar
Martin Finkel committed
228

229

230
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
231 232 233
                EntryPoint = "libvlc_set_fullscreen")]
            internal static extern void LibVLCSetFullscreen(IntPtr mediaPlayer, int fullscreen);

234

235
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
236 237 238
                EntryPoint = "libvlc_get_fullscreen")]
            internal static extern int LibVLCGetFullscreen(IntPtr mediaPlayer);

239

240
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
241 242 243
                EntryPoint = "libvlc_toggle_teletext")]
            internal static extern void LibVLCToggleTeletext(IntPtr mediaPlayer);

244

245
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
246 247 248
                EntryPoint = "libvlc_media_player_set_equalizer")]
            internal static extern int LibVLCMediaPlayerSetEqualizer(IntPtr mediaPlayer, IntPtr equalizer);

249
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
250
                EntryPoint = "libvlc_audio_set_callbacks")]
251 252
            internal static extern void LibVLCAudioSetCallbacks(IntPtr mediaPlayer, LibVLCAudioPlayCb play, LibVLCAudioPauseCb? pause,
                LibVLCAudioResumeCb? resume, LibVLCAudioFlushCb? flush, LibVLCAudioDrainCb? drain, IntPtr opaque);
253

254
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
255
                EntryPoint = "libvlc_audio_set_volume_callback")]
256
            internal static extern void LibVLCAudioSetVolumeCallback(IntPtr mediaPlayer, LibVLCVolumeCb? volumeCallback);
257

258
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
259
                EntryPoint = "libvlc_audio_set_format_callbacks")]
260
            internal static extern void LibVLCAudioSetFormatCallbacks(IntPtr mediaPlayer, LibVLCAudioSetupCb setup, LibVLCAudioCleanupCb? cleanup);
Martin Finkel's avatar
Martin Finkel committed
261

262
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
263
                EntryPoint = "libvlc_audio_set_format")]
Martin Finkel's avatar
Martin Finkel committed
264
            internal static extern void LibVLCAudioSetFormat(IntPtr mediaPlayer, IntPtr format,
Martin Finkel's avatar
Martin Finkel committed
265 266
                uint rate, uint channels);

267
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
268 269 270
                EntryPoint = "libvlc_audio_output_device_enum")]
            internal static extern IntPtr LibVLCAudioOutputDeviceEnum(IntPtr mediaPlayer);

271
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
272
                EntryPoint = "libvlc_audio_output_device_set")]
Martin Finkel's avatar
Martin Finkel committed
273
            internal static extern void LibVLCAudioOutputDeviceSet(IntPtr mediaPlayer, IntPtr module, IntPtr deviceId);
274

275 276 277 278
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
                EntryPoint = "libvlc_audio_output_device_get")]
            internal static extern IntPtr LibVLCAudioOutputDeviceGet(IntPtr mediaPlayer);

279
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
280
                EntryPoint = "libvlc_audio_output_set")]
Martin Finkel's avatar
Martin Finkel committed
281
            internal static extern int LibVLCAudioOutputSet(IntPtr mediaPlayer, IntPtr name);
Martin Finkel's avatar
Martin Finkel committed
282

283

284
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
285 286 287
                EntryPoint = "libvlc_audio_toggle_mute")]
            internal static extern void LibVLCAudioToggleMute(IntPtr mediaPlayer);

288

289
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
290 291 292
                EntryPoint = "libvlc_audio_get_mute")]
            internal static extern int LibVLCAudioGetMute(IntPtr mediaPlayer);

293

294
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
295 296 297
                EntryPoint = "libvlc_audio_set_mute")]
            internal static extern void LibVLCAudioSetMute(IntPtr mediaPlayer, int status);

298

299
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
300 301 302
                EntryPoint = "libvlc_audio_get_volume")]
            internal static extern int LibVLCAudioGetVolume(IntPtr mediaPlayer);

303

304
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
305 306 307
                EntryPoint = "libvlc_audio_set_volume")]
            internal static extern int LibVLCAudioSetVolume(IntPtr mediaPlayer, int volume);

308

309
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
310 311 312
                EntryPoint = "libvlc_audio_get_track_count")]
            internal static extern int LibVLCAudioGetTrackCount(IntPtr mediaPlayer);

313

314
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
315 316 317
                EntryPoint = "libvlc_audio_get_track_description")]
            internal static extern IntPtr LibVLCAudioGetTrackDescription(IntPtr mediaPlayer);

318

319
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
320 321 322
                EntryPoint = "libvlc_audio_get_track")]
            internal static extern int LibVLCAudioGetTrack(IntPtr mediaPlayer);

323

324
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
325 326 327
                EntryPoint = "libvlc_audio_set_track")]
            internal static extern int LibVLCAudioSetTrack(IntPtr mediaPlayer, int track);

328

329
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
330
                EntryPoint = "libvlc_audio_get_channel")]
331
            internal static extern AudioOutputChannel LibVLCAudioGetChannel(IntPtr mediaPlayer);
Martin Finkel's avatar
Martin Finkel committed
332

333

334
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
335
                EntryPoint = "libvlc_audio_set_channel")]
336
            internal static extern int LibVLCAudioSetChannel(IntPtr mediaPlayer, AudioOutputChannel channel);
Martin Finkel's avatar
Martin Finkel committed
337

338

339
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
340 341 342
                EntryPoint = "libvlc_audio_get_delay")]
            internal static extern long LibVLCAudioGetDelay(IntPtr mediaPlayer);

343

344
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
345 346 347
                EntryPoint = "libvlc_audio_set_delay")]
            internal static extern int LibVLCAudioSetDelay(IntPtr mediaPlayer, long delay);

348
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
349
                EntryPoint = "libvlc_video_set_callbacks")]
Martin Finkel's avatar
Martin Finkel committed
350
            internal static extern void LibVLCVideoSetCallbacks(IntPtr mediaPlayer, LibVLCVideoLockCb lockCallback,
351
                LibVLCVideoUnlockCb? unlock, LibVLCVideoDisplayCb? display, IntPtr opaque);
Martin Finkel's avatar
Martin Finkel committed
352

353
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
354
                EntryPoint = "libvlc_video_set_format")]
Martin Finkel's avatar
Martin Finkel committed
355
            internal static extern void LibVLCVideoSetFormat(IntPtr mediaPlayer, IntPtr chroma,
Martin Finkel's avatar
Martin Finkel committed
356 357
                uint width, uint height, uint pitch);

358
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
359
                EntryPoint = "libvlc_video_set_format_callbacks")]
Martin Finkel's avatar
Martin Finkel committed
360
            internal static extern void LibVLCVideoSetFormatCallbacks(IntPtr mediaPlayer, LibVLCVideoFormatCb setup,
361
                LibVLCVideoCleanupCb? cleanup);
Martin Finkel's avatar
Martin Finkel committed
362

363

364
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
365 366 367
                EntryPoint = "libvlc_video_set_key_input")]
            internal static extern void LibVLCVideoSetKeyInput(IntPtr mediaPlayer, int enable);

368

369
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
370 371 372
                EntryPoint = "libvlc_video_set_mouse_input")]
            internal static extern void LibVLCVideoSetMouseInput(IntPtr mediaPlayer, int enable);

373

374
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
375
                EntryPoint = "libvlc_video_get_size")]
376
            internal static extern int LibVLCVideoGetSize(IntPtr mediaPlayer, uint num, ref uint px, ref uint py);
Martin Finkel's avatar
Martin Finkel committed
377

378

379
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
380
                EntryPoint = "libvlc_video_get_cursor")]
381
            internal static extern int LibVLCVideoGetCursor(IntPtr mediaPlayer, uint num, ref int px, ref int py);
Martin Finkel's avatar
Martin Finkel committed
382

383

384
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
385 386 387
                EntryPoint = "libvlc_video_get_scale")]
            internal static extern float LibVLCVideoGetScale(IntPtr mediaPlayer);

388

389
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
390 391 392
                EntryPoint = "libvlc_video_set_scale")]
            internal static extern void LibVLCVideoSetScale(IntPtr mediaPlayer, float factor);

393

394
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
395
                EntryPoint = "libvlc_video_get_aspect_ratio")]
Martin Finkel's avatar
Martin Finkel committed
396
            internal static extern IntPtr LibVLCVideoGetAspectRatio(IntPtr mediaPlayer);
397

398
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
399
                EntryPoint = "libvlc_video_set_aspect_ratio")]
Martin Finkel's avatar
Martin Finkel committed
400
            internal static extern void LibVLCVideoSetAspectRatio(IntPtr mediaPlayer, IntPtr aspect);
Martin Finkel's avatar
Martin Finkel committed
401

402

403
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
404 405 406
                EntryPoint = "libvlc_video_get_spu")]
            internal static extern int LibVLCVideoGetSpu(IntPtr mediaPlayer);

407

408
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
409 410 411
                EntryPoint = "libvlc_video_get_spu_count")]
            internal static extern int LibVLCVideoGetSpuCount(IntPtr mediaPlayer);

412

413
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
414 415 416
                EntryPoint = "libvlc_video_get_spu_description")]
            internal static extern IntPtr LibVLCVideoGetSpuDescription(IntPtr mediaPlayer);

417

418
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
419 420 421
                EntryPoint = "libvlc_video_set_spu")]
            internal static extern int LibVLCVideoSetSpu(IntPtr mediaPlayer, int spu);

422
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
423 424 425
                EntryPoint = "libvlc_video_get_spu_delay")]
            internal static extern long LibVLCVideoGetSpuDelay(IntPtr mediaPlayer);

426

427
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
428 429 430
                EntryPoint = "libvlc_video_set_spu_delay")]
            internal static extern int LibVLCVideoSetSpuDelay(IntPtr mediaPlayer, long delay);

431

432
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
433 434 435
                EntryPoint = "libvlc_video_get_title_description")]
            internal static extern IntPtr LibVLCVideoGetTitleDescription(IntPtr mediaPlayer);

436

437
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
438 439
                EntryPoint = "libvlc_media_player_get_full_title_descriptions")]
            internal static extern int LibVLCMediaPlayerGetFullTitleDescriptions(IntPtr mediaPlayer, IntPtr titles);
Martin Finkel's avatar
Martin Finkel committed
440

441

442
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
443 444 445 446
                EntryPoint = "libvlc_video_get_chapter_description")]
            internal static extern IntPtr LibVLCVideoGetChapterDescription(IntPtr mediaPlayer,
                int title);

447

448
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
449 450 451
                EntryPoint = "libvlc_title_descriptions_release")]
            internal static extern void LibVLCTitleDescriptionsRelease(IntPtr titles, uint count);

452

453
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
454
                EntryPoint = "libvlc_media_player_get_full_chapter_descriptions")]
455
            internal static extern int LibVLCMediaPlayerGetFullChapterDescriptions(IntPtr mediaPlayer, int titleIndex, out IntPtr chapters);
Martin Finkel's avatar
Martin Finkel committed
456

457

458
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
459 460
                EntryPoint = "libvlc_chapter_descriptions_release")]
            internal static extern void LibVLCChapterDescriptionsRelease(IntPtr chapters, uint count);
Martin Finkel's avatar
Martin Finkel committed
461

462

463
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
464
                EntryPoint = "libvlc_video_get_crop_geometry")]
Martin Finkel's avatar
Martin Finkel committed
465
            internal static extern IntPtr LibVLCVideoGetCropGeometry(IntPtr mediaPlayer);
466

467
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
468
                EntryPoint = "libvlc_video_set_crop_geometry")]
Martin Finkel's avatar
Martin Finkel committed
469
            internal static extern void LibVLCVideoSetCropGeometry(IntPtr mediaPlayer, IntPtr geometry);
470

471
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
472 473 474
                EntryPoint = "libvlc_video_get_teletext")]
            internal static extern int LibVLCVideoGetTeletext(IntPtr mediaPlayer);

475

476
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
477 478 479
                EntryPoint = "libvlc_video_set_teletext")]
            internal static extern void LibVLCVideoSetTeletext(IntPtr mediaPlayer, int page);

480

481
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
482 483 484
                EntryPoint = "libvlc_video_get_track_count")]
            internal static extern int LibVLCVideoGetTrackCount(IntPtr mediaPlayer);

485
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
486 487 488
                EntryPoint = "libvlc_video_get_track_description")]
            internal static extern IntPtr LibVLCVideoGetTrackDescription(IntPtr mediaPlayer);

489
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
490 491 492
                EntryPoint = "libvlc_video_get_track")]
            internal static extern int LibVLCVideoGetTrack(IntPtr mediaPlayer);

493
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
494 495
                EntryPoint = "libvlc_video_set_track")]
            internal static extern int LibVLCVideoSetTrack(IntPtr mediaPlayer, int track);
Martin Finkel's avatar
Martin Finkel committed
496

497
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
498
                EntryPoint = "libvlc_video_take_snapshot")]
Martin Finkel's avatar
Martin Finkel committed
499
            internal static extern int LibVLCVideoTakeSnapshot(IntPtr mediaPlayer, uint num,
Martin Finkel's avatar
Martin Finkel committed
500
                IntPtr filepath, uint width, uint height);
501

502
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
503
                EntryPoint = "libvlc_video_set_deinterlace")]
Martin Finkel's avatar
Martin Finkel committed
504
            internal static extern void LibVLCVideoSetDeinterlace(IntPtr mediaPlayer, IntPtr mode);
Martin Finkel's avatar
Martin Finkel committed
505

506
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
507
                EntryPoint = "libvlc_video_get_marquee_int")]
508
            internal static extern int LibVLCVideoGetMarqueeInt(IntPtr mediaPlayer, VideoMarqueeOption option);
Martin Finkel's avatar
Martin Finkel committed
509

510
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
511
                EntryPoint = "libvlc_video_get_marquee_string")]
Martin Finkel's avatar
Martin Finkel committed
512
            internal static extern IntPtr LibVLCVideoGetMarqueeString(IntPtr mediaPlayer, VideoMarqueeOption option);
513

514
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
515
                EntryPoint = "libvlc_video_set_marquee_int")]
516
            internal static extern void LibVLCVideoSetMarqueeInt(IntPtr mediaPlayer, VideoMarqueeOption option, int marqueeValue);
Martin Finkel's avatar
Martin Finkel committed
517

518
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
519
                EntryPoint = "libvlc_video_set_marquee_string")]
Martin Finkel's avatar
Martin Finkel committed
520
            internal static extern void LibVLCVideoSetMarqueeString(IntPtr mediaPlayer, VideoMarqueeOption option, IntPtr marqueeValue);
521

522
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
523
                EntryPoint = "libvlc_video_get_logo_int")]
524
            internal static extern int LibVLCVideoGetLogoInt(IntPtr mediaPlayer, VideoLogoOption option);
Martin Finkel's avatar
Martin Finkel committed
525

526
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
527
                EntryPoint = "libvlc_video_set_logo_int")]
528
            internal static extern void LibVLCVideoSetLogoInt(IntPtr mediaPlayer, VideoLogoOption option, int value);
Martin Finkel's avatar
Martin Finkel committed
529

530
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
531
                EntryPoint = "libvlc_video_set_logo_string")]
Martin Finkel's avatar
Martin Finkel committed
532
            internal static extern void LibVLCVideoSetLogoString(IntPtr mediaPlayer, VideoLogoOption option, IntPtr logoOptionValue);
533

534
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
535
                EntryPoint = "libvlc_video_get_adjust_int")]
536
            internal static extern int LibVLCVideoGetAdjustInt(IntPtr mediaPlayer, VideoAdjustOption option);
Martin Finkel's avatar
Martin Finkel committed
537

538
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
539
                EntryPoint = "libvlc_video_set_adjust_int")]
540
            internal static extern void LibVLCVideoSetAdjustInt(IntPtr mediaPlayer, VideoAdjustOption option, int value);
Martin Finkel's avatar
Martin Finkel committed
541

542
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
543
                EntryPoint = "libvlc_video_get_adjust_float")]
544
            internal static extern float LibVLCVideoGetAdjustFloat(IntPtr mediaPlayer, VideoAdjustOption option);
Martin Finkel's avatar
Martin Finkel committed
545

546
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
547
                EntryPoint = "libvlc_video_set_adjust_float")]
548
            internal static extern void LibVLCVideoSetAdjustFloat(IntPtr mediaPlayer, VideoAdjustOption option, float value);
Martin Finkel's avatar
Martin Finkel committed
549

550
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
551
                EntryPoint = "libvlc_media_player_add_slave")]
Martin Finkel's avatar
Martin Finkel committed
552
            internal static extern int LibVLCMediaPlayerAddSlave(IntPtr mediaPlayer, MediaSlaveType mediaSlaveType,
Martin Finkel's avatar
Martin Finkel committed
553
                IntPtr uri, bool selectWhenloaded);
Martin Finkel's avatar
Martin Finkel committed
554

555
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
556 557
                EntryPoint = "libvlc_video_new_viewpoint")]
            internal static extern IntPtr LibVLCVideoNewViewpoint();
558

559
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
560
                EntryPoint = "libvlc_video_update_viewpoint")]
561
            internal static extern int LibVLCVideoUpdateViewpoint(IntPtr mediaPlayer, IntPtr viewpoint, bool absolute);
Martin Finkel's avatar
Martin Finkel committed
562

563

564
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
Martin Finkel's avatar
Martin Finkel committed
565 566
                EntryPoint = "libvlc_track_description_list_release")]
            internal static extern void LibVLCTrackDescriptionListRelease(IntPtr trackDescription);
567

568

569
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
570 571
                EntryPoint = "libvlc_audio_output_device_list_release")]
            internal static extern void LibVLCAudioOutputDeviceListRelease(IntPtr list);
572

573

574
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
575 576
                EntryPoint = "libvlc_media_player_set_renderer")]
            internal static extern int LibVLCMediaPlayerSetRenderer(IntPtr mediaplayer, IntPtr renderItem);
577

Martin Finkel's avatar
Martin Finkel committed
578 579 580 581 582 583 584 585
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
                EntryPoint = "libvlc_media_player_get_role")]
            internal static extern MediaPlayerRole LibVLCMediaPlayerGetRole(IntPtr mediaplayer);

            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
                EntryPoint = "libvlc_media_player_set_role")]
            internal static extern int LibVLCMediaPlayerSetRole(IntPtr mediaplayer, MediaPlayerRole role);

586 587 588
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
                EntryPoint = "libvlc_media_player_retain")]
            internal static extern void LibVLCMediaPlayerRetain(IntPtr mediaplayer);
589
#if ANDROID
590

591
            [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
592 593
                EntryPoint = "libvlc_media_player_set_android_context")]
            internal static extern void LibVLCMediaPlayerSetAndroidContext(IntPtr mediaPlayer, IntPtr aWindow);
594
#endif
Martin Finkel's avatar
Martin Finkel committed
595
        }
Martin Finkel's avatar
Martin Finkel committed
596

597
        MediaPlayerEventManager? _eventManager;
Martin Finkel's avatar
Martin Finkel committed
598

599 600 601 602 603
        /// <summary>
        /// The GCHandle to be passed to callbacks as userData
        /// </summary>
        GCHandle _gcHandle;

Martin Finkel's avatar
Martin Finkel committed
604
        /// <summary>Create an empty Media Player object</summary>
Martin Finkel's avatar
Martin Finkel committed
605
        /// <param name="libVLC">
Martin Finkel's avatar
Martin Finkel committed
606 607 608 609
        /// <para>the libvlc instance in which the Media Player</para>
        /// <para>should be created.</para>
        /// </param>
        /// <returns>a new media player object, or NULL on error.</returns>
Martin Finkel's avatar
Martin Finkel committed
610
        public MediaPlayer(LibVLC libVLC)
611
            : base(() => Native.LibVLCMediaPlayerNew(libVLC.NativeReference), Native.LibVLCMediaPlayerRelease)
Martin Finkel's avatar
Martin Finkel committed
612
        {
613
            _gcHandle = GCHandle.Alloc(this);
Martin Finkel's avatar
Martin Finkel committed
614 615 616 617 618 619 620 621 622 623 624
        }

        /// <summary>Create a Media Player object from a Media</summary>
        /// <param name="media">
        /// <para>the media. Afterwards the p_md can be safely</para>
        /// <para>destroyed.</para>
        /// </param>
        /// <returns>a new media player object, or NULL on error.</returns>
        public MediaPlayer(Media media)
            : base(() => Native.LibVLCMediaPlayerNewFromMedia(media.NativeReference), Native.LibVLCMediaPlayerRelease)
        {
625
            _gcHandle = GCHandle.Alloc(this);
Martin Finkel's avatar
Martin Finkel committed
626
        }
627

Martin Finkel's avatar
Martin Finkel committed
628
        /// <summary>
Martin Finkel's avatar
Martin Finkel committed
629
        /// Get the media used by the media_player.
630
        /// Set the media that will be used by the media_player.
Martin Finkel's avatar
Martin Finkel committed
631
        /// If any, previous md will be released.
632
        /// Note: It is safe to release the Media on the C# side after it's been set on the MediaPlayer successfully
Martin Finkel's avatar
Martin Finkel committed
633
        /// </summary>
634
        public Media? Media
Martin Finkel's avatar
Martin Finkel committed
635 636 637 638 639 640
        {
            get
            {
                var mediaPtr = Native.LibVLCMediaPlayerGetMedia(NativeReference);
                return mediaPtr == IntPtr.Zero ? null : new Media(mediaPtr);
            }
641
            set => Native.LibVLCMediaPlayerSetMedia(NativeReference, value?.NativeReference ?? IntPtr.Zero);
Martin Finkel's avatar
Martin Finkel committed
642 643 644 645 646 647 648 649
        }

        /// <summary>
        /// return true if the media player is playing, false otherwise
        /// </summary>
        public bool IsPlaying => Native.LibVLCMediaPlayerIsPlaying(NativeReference) != 0;

        /// <summary>
650
        /// Start playback with Media that is set
Martin Finkel's avatar
Martin Finkel committed
651 652
        /// If playback was already started, this method has no effect
        /// </summary>
653
        /// <returns>true if successful</returns>
654 655 656 657 658
        public bool Play()
        {
            Media?.AddOption(Configuration);
            return Native.LibVLCMediaPlayerPlay(NativeReference) == 0;
        }
Martin Finkel's avatar
Martin Finkel committed
659

660 661 662 663 664
        /// <summary>
        /// Set media and start playback
        /// </summary>
        /// <param name="media"></param>
        /// <returns>true if successful</returns>
Martin Finkel's avatar
Martin Finkel committed
665 666 667 668 669 670
        public bool Play(Media media)
        {
            Media = media;
            return Play();
        }

Martin Finkel's avatar
Martin Finkel committed
671 672 673 674 675
        /// <summary>
        /// Pause or resume (no effect if there is no media).
        /// version LibVLC 1.1.1 or later
        /// </summary>
        /// <param name="pause">play/resume if true, pause if false</param>