]> git.sesse.net Git - vlc/blob - bindings/cil/tests/testvlc.cs
Add media and player state support
[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 at    {0}", m.Location);
34             Console.WriteLine (" duration:  {0}µs", m.Duration);
35             Console.WriteLine (" preparsed: {0}", m.IsPreparsed);
36             Console.WriteLine (" state:     {0}", m.State);
37         }
38
39         private static void DumpPlayer (Player p)
40         {
41             if (!p.IsPlaying)
42                 return;
43
44             int percent = (int)(p.Position * 100);
45             Console.Write ("{0}: {1} of {2} ms ({3}%)\r", p.State,
46                            p.Time, p.Length, percent);
47         }
48
49         private static void Sleep (int msec)
50         {
51             System.Threading.Thread.Sleep (msec);
52         }
53
54         public static int Main (string[] args)
55         {
56             string[] argv = new string[]{
57                 "-vv", "-I", "dummy", "--plugin-path=../../modules"
58             };
59
60             Console.WriteLine ("Running on LibVLC {0} ({1})", VLC.Version,
61                                VLC.ChangeSet);
62             Console.WriteLine (" (compiled with {0})", VLC.Compiler);
63
64             VLC vlc = new VLC (argv);
65             foreach (string mrl in args)
66             {
67                 Media media = new Media (vlc, mrl);
68                 Player player = new Player (media);
69
70                 DumpMedia (media);
71                 DumpMedia ((Media)media.Clone ());
72
73                 player.Play ();
74                 do
75                 {
76                     DumpPlayer (player);
77                     Sleep (500);
78                 }
79                 while (player.IsPlaying);
80                 player.Stop ();
81                 media.Dispose ();
82                 player.Dispose ();
83             }
84
85             vlc.Dispose ();
86             return 0;
87         }
88     };
89 };