/
HowToUse_Dll.cs
219 lines (182 loc) · 7.86 KB
/
HowToUse_Dll.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Microsoft Visual C# example
//
// To make this example working, you must put MediaInfo.Dll and Example.ogg
// in the "./Bin/__ConfigurationName__" folder
// and add MediaInfoDll.cs to your project
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.IO;
using MediaInfoLib;
namespace MediaInfoLib_MSCS
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox richTextBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Methode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(0, 0);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(768, 512);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// Form1
//
this.ClientSize = new System.Drawing.Size(770, 514);
this.Controls.Add(this.richTextBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "How to use MediaInfo.Dll";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
//Test if version of DLL is compatible : 3rd argument is "version of DLL tested;Your application name;Your application version"
String ToDisplay;
MediaInfo MI = new MediaInfo();
ToDisplay = MI.Option("Info_Version", "0.7.0.0;MediaInfoDLL_Example_CS;0.7.0.0");
if (ToDisplay.Length == 0)
{
richTextBox1.Text = "MediaInfo.Dll: this version of the DLL is not compatible";
return;
}
//Information about MediaInfo
ToDisplay += "\r\n\r\nInfo_Parameters\r\n";
ToDisplay += MI.Option("Info_Parameters");
ToDisplay += "\r\n\r\nInfo_Capacities\r\n";
ToDisplay += MI.Option("Info_Capacities");
ToDisplay += "\r\n\r\nInfo_Codecs\r\n";
ToDisplay += MI.Option("Info_Codecs");
//An example of how to use the library
ToDisplay += "\r\n\r\nOpen\r\n";
MI.Open("Example.ogg");
ToDisplay += "\r\n\r\nInform with Complete=false\r\n";
MI.Option("Complete");
ToDisplay += MI.Inform();
ToDisplay += "\r\n\r\nInform with Complete=true\r\n";
MI.Option("Complete", "1");
ToDisplay += MI.Inform();
ToDisplay += "\r\n\r\nCustom Inform\r\n";
MI.Option("Inform", "General;File size is %FileSize% bytes");
ToDisplay += MI.Inform();
ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='FileSize'\r\n";
ToDisplay += MI.Get(0, 0, "FileSize");
ToDisplay += "\r\n\r\nGet with Stream=General and Parameter=46\r\n";
ToDisplay += MI.Get(0, 0, 46);
ToDisplay += "\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n";
ToDisplay += MI.Count_Get(StreamKind.Audio);
ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='AudioCount'\r\n";
ToDisplay += MI.Get(StreamKind.General, 0, "AudioCount");
ToDisplay += "\r\n\r\nGet with Stream=Audio and Parameter='StreamCount'\r\n";
ToDisplay += MI.Get(StreamKind.Audio, 0, "StreamCount");
ToDisplay += "\r\n\r\nClose\r\n";
MI.Close();
//Example with a stream
//ToDisplay+="\r\n"+ExampleWithStream()+"\r\n";
//Displaying the text
richTextBox1.Text = ToDisplay;
}
String ExampleWithStream()
{
//Initilaizing MediaInfo
MediaInfo MI = new MediaInfo();
//From: preparing an example file for reading
FileStream From = new FileStream("Example.ogg", FileMode.Open, FileAccess.Read);
//From: preparing a memory buffer for reading
byte[] From_Buffer = new byte[64*1024];
int From_Buffer_Size; //The size of the read file buffer
//Preparing to fill MediaInfo with a buffer
MI.Open_Buffer_Init(From.Length, 0);
//The parsing loop
do
{
//Reading data somewhere, do what you want for this.
From_Buffer_Size = From.Read(From_Buffer, 0, 64 * 1024);
//Sending the buffer to MediaInfo
System.Runtime.InteropServices.GCHandle GC = System.Runtime.InteropServices.GCHandle.Alloc(From_Buffer, System.Runtime.InteropServices.GCHandleType.Pinned);
IntPtr From_Buffer_IntPtr = GC.AddrOfPinnedObject();
Status Result = (Status)MI.Open_Buffer_Continue(From_Buffer_IntPtr, (IntPtr)From_Buffer_Size);
GC.Free();
if ((Result & Status.Finalized) == Status.Finalized)
break;
//Testing if MediaInfo request to go elsewhere
if (MI.Open_Buffer_Continue_GoTo_Get() != -1)
{
Int64 Position = From.Seek(MI.Open_Buffer_Continue_GoTo_Get(), SeekOrigin.Begin); //Position the file
MI.Open_Buffer_Init(From.Length, Position); //Informing MediaInfo we have seek
}
}
while (From_Buffer_Size > 0);
//Finalizing
MI.Open_Buffer_Finalize(); //This is the end of the stream, MediaInfo must finnish some work
//Get() example
return "Container format is " + MI.Get(StreamKind.General, 0, "Format");
}
}
}