]> git.sesse.net Git - vlc/blob - bindings/cil/src/player.cs
Explicit native exception methods scope
[vlc] / bindings / cil / src / player.cs
1 /**
2  * @file player.cs
3  * @brief Media player class
4  * @ingroup API
5  *
6  * @defgroup API Managed interface to LibVLC
7  * This is the primary class library for .NET applications
8  * to embed and control LibVLC.
9  *
10  * @defgroup Internals LibVLC internals
11  * This covers internal marshalling functions to use the native LibVLC.
12  * Only VLC developpers should need to read this section.
13  */
14
15 /**********************************************************************
16  *  Copyright (C) 2009 RĂ©mi Denis-Courmont.                           *
17  *  This program is free software; you can redistribute and/or modify *
18  *  it under the terms of the GNU General Public License as published *
19  *  by the Free Software Foundation; version 2 of the license, or (at *
20  *  your option) any later version.                                   *
21  *                                                                    *
22  *  This program is distributed in the hope that it will be useful,   *
23  *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *
24  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              *
25  *  See the GNU General Public License for more details.              *
26  *                                                                    *
27  *  You should have received a copy of the GNU General Public License *
28  *  along with this program; if not, you can get it from:             *
29  *  http://www.gnu.org/copyleft/gpl.html                              *
30  **********************************************************************/
31
32 using System;
33 using System.Runtime.InteropServices;
34
35 namespace VideoLAN.LibVLC
36 {
37    /**
38      * @brief MediaPlayerHandle: unmanaged LibVLC media player pointer
39      * @ingroup Internals
40      */
41     internal sealed class MediaPlayerHandle : NonNullHandle
42     {
43         [DllImport ("libvlc.dll",
44                     EntryPoint="libvlc_media_player_new")]
45         internal static extern
46         MediaPlayerHandle Create (InstanceHandle inst, NativeException ex);
47         [DllImport ("libvlc.dll",
48                     EntryPoint="libvlc_media_player_new_from_media")]
49         internal static extern
50         MediaPlayerHandle Create (MediaHandle media, NativeException ex);
51
52         [DllImport ("libvlc.dll",
53                     EntryPoint="libvlc_media_player_release")]
54         internal static extern void Release (IntPtr ptr);
55
56         [DllImport ("libvlc.dll",
57                     EntryPoint="libvlc_media_player_set_media")]
58         internal static extern
59         MediaPlayerHandle SetMedia (MediaPlayerHandle player,
60                                     MediaHandle media,
61                                     NativeException ex);
62
63         protected override void Destroy ()
64         {
65             Release (handle);
66         }
67     };
68
69     /**
70      * @brief MediaPlayer: a simple media player
71      * Use this class to play a media.
72      */
73     public class MediaPlayer : BaseObject
74     {
75         internal MediaPlayerHandle Handle
76         {
77             get
78             {
79                 return handle as MediaPlayerHandle;
80             }
81         }
82
83         Media media; /**< Active media */
84         /**
85          * The Media object that the MediaPlayer is using,
86          * or null if there is none.
87          */
88         public Media Media
89         {
90             get
91             {
92                 return media;
93             }
94             set
95             {
96                 MediaHandle mh = (value != null) ? value.Handle : null;
97
98                 MediaPlayerHandle.SetMedia (Handle, mh, null);
99                 media = value;
100             }
101         }
102
103         /**
104          * Creates an empty MediaPlayer object.
105          * An input media will be needed before this media player can be used.
106          *
107          * @param instance VLC instance
108          */
109         public MediaPlayer (VLC instance)
110         {
111             this.media = null;
112             handle = MediaPlayerHandle.Create (instance.Handle, ex);
113             ex.Raise ();
114         }
115
116         /**
117          * Creates a MediaPlayer object from a Media object.
118          * This allows playing the specified media.
119          *
120          * @param media media object
121          */
122         public MediaPlayer (Media media)
123         {
124             this.media = media;
125             handle = MediaPlayerHandle.Create (media.Handle, ex);
126             ex.Raise ();
127         }
128
129     };
130 };