]> git.sesse.net Git - vlc/blob - bindings/cil/tests/testvlc.cs
9ea8a3188a32cc14da8b0b0b501b6dfc8b68deb6
[vlc] / bindings / cil / tests / testvlc.cs
1 /*
2  * testvlc.cs - tests for libvlc CIL bindings
3  *
4  * $Id$
5  */
6
7 /**********************************************************************
8  *  Copyright (C) 2007 RĂ©mi Denis-Courmont.                           *
9  *  This program is free software; you can redistribute and/or modify *
10  *  it under the terms of the GNU General Public License as published *
11  *  by the Free Software Foundation; version 2 of the license, or (at *
12  *  your option) any later version.                                   *
13  *                                                                    *
14  *  This program is distributed in the hope that it will be useful,   *
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              *
17  *  See the GNU General Public License for more details.              *
18  *                                                                    *
19  *  You should have received a copy of the GNU General Public License *
20  *  along with this program; if not, you can get it from:             *
21  *  http://www.gnu.org/copyleft/gpl.html                              *
22  **********************************************************************/
23
24 using System;
25 using VideoLAN.LibVLC;
26
27 namespace VideoLAN.LibVLC.Test
28 {
29     public sealed class Test
30     {
31         private static void DumpMedia (Media m)
32         {
33             Console.WriteLine ("Media: {0} {1} (duration: {2}, {3}preparsed)",
34                                m.State, m.Location, m.Duration,
35                                m.IsPreparsed ? "" : "not ");
36         }
37
38         private static void WriteMediaState (Media m, State s)
39         {
40             Console.WriteLine (" -> {0}", s);
41         }
42
43         private static void DumpPlayer (Player p)
44         {
45             if (!p.IsPlaying)
46                 return;
47
48             int percent = (int)(p.Position * 100);
49             Console.Write ("{0}: {1} of {2} ms ({3}%)\r", p.State,
50                            p.Time, p.Length, percent);
51         }
52
53         private static void Sleep (int msec)
54         {
55             System.Threading.Thread.Sleep (msec);
56         }
57
58         public static int Main (string[] args)
59         {
60             string[] argv = new string[]{
61                 "-vv", "-I", "dummy", "--plugin-path=../../modules"
62             };
63
64             Console.WriteLine ("Running on LibVLC {0} ({1})", VLC.Version,
65                                VLC.ChangeSet);
66             Console.WriteLine (" (compiled with {0})", VLC.Compiler);
67
68             VLC vlc = new VLC (argv);
69             foreach (string mrl in args)
70             {
71                 Media media = new Media (vlc, mrl);
72                 Player player = new Player (media);
73
74                 DumpMedia (media);
75                 DumpMedia ((Media)media.Clone ());
76                 media.StateChanged += WriteMediaState;
77
78                 /*foreach (MetaType type in Enum.GetValues (typeof (MetaType)))
79                 {
80                     string meta = media.GetMeta (type);
81                     if (meta != null)
82                         Console.WriteLine (" {0}: {1}", type, meta);
83                 }*/
84
85                 player.Play ();
86                 do
87                 {
88                     DumpPlayer (player);
89                     Sleep (500);
90                 }
91                 while (player.IsPlaying);
92                 player.Stop ();
93                 media.Dispose ();
94                 player.Dispose ();
95             }
96
97             vlc.Dispose ();
98             return 0;
99         }
100     };
101 };