Skip to content

Commit f93e588

Browse files
committed
Ruby interface
Signed-off-by: Maxime Gervais <gervais.maxime@gmail.com>
1 parent f947575 commit f93e588

2 files changed

Lines changed: 451 additions & 0 deletions

File tree

Source/Example/HowToUse_Dll.rb

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
## Copyright (c) MediaArea.net SARL. All Rights Reserved.
2+
#
3+
# Use of this source code is governed by a BSD-style license that can
4+
# be found in the License.html file in the root of the source tree.
5+
##
6+
7+
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8+
#
9+
# Ruby example
10+
#
11+
# To make this example working, you must put the MediaInfoDLL.rb and
12+
# example.ogg in the same folder, then run:
13+
# ruby HowToUse_Dll.rb
14+
# The MediaInfo library must reside in a standard library path (e.g.
15+
# C:\Windows\System32\MediaInfo.dll on Windows), if this isn't the case set
16+
# the LIBMEDIAINFO_PATH environment variable to the right library path.
17+
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18+
19+
20+
require './MediaInfoDLL.rb'
21+
22+
mi=MediaInfo::MediaInfo.new
23+
24+
#Information about MediaInfo
25+
puts "Info_Parameters"
26+
puts mi.Option "Info_Parameters"
27+
28+
puts ""
29+
puts "Info_Codecs"
30+
puts mi.Option "Info_Codecs"
31+
32+
#An example of how to use the library
33+
puts ""
34+
puts "Open"
35+
mi.Open "Example.ogg"
36+
37+
puts ""
38+
puts "Inform with Complete=false"
39+
mi.Option "Complete"
40+
puts mi.Inform
41+
42+
puts ""
43+
puts "Inform with Complete=true"
44+
puts mi.Option "Complete", "1"
45+
puts mi.Inform
46+
47+
puts ""
48+
puts "Custom Inform"
49+
mi.Option "Inform", "General;Example : FileSize=%FileSize%"
50+
puts mi.Inform
51+
52+
puts ""
53+
puts "Get with Stream=General and Parameter='FileSize'"
54+
puts mi.Get :General, 0, "FileSize"
55+
56+
puts ""
57+
puts "Get with Stream=General and Parameter=46"
58+
puts mi.Get :General, 0, 46
59+
60+
puts ""
61+
puts "Count_Get with StreamKind=Stream_Audio"
62+
puts mi.Count_Get :Audio
63+
64+
puts ""
65+
puts "Get with Stream=General and Parameter='AudioCount'"
66+
puts mi.Get :General, 0, "AudioCount"
67+
68+
puts ""
69+
puts "Get with Stream=Audio and Parameter='StreamCount'"
70+
puts mi.Get :Audio, 0, "StreamCount"
71+
72+
puts ""
73+
puts "Close"
74+
mi.Close
75+
76+
#By buffer example
77+
78+
#Open example file for reading
79+
File.open("Example.ogg", "r") do |file|
80+
puts ""
81+
puts "Open_Buffer_Init"
82+
mi.Open_Buffer_Init file.size, 0
83+
84+
puts ""
85+
puts "Parsing loop"
86+
while true
87+
buffer=file.read(7*188)
88+
if buffer
89+
#Send the buffer to MediaInfo
90+
status=mi.Open_Buffer_Continue buffer, buffer.bytesize
91+
92+
if (status & 0x08) #Bit3=Finished
93+
break
94+
end
95+
96+
#Test if there is a MediaInfo request to go elsewhere
97+
seek=mi.Open_Buffer_Continue_GoTo_Get
98+
if seek != -1 + (2 ** 64) # equal to (uint64)-1 in C/C++
99+
file.seek seek #Seek the file
100+
mi.Open_Buffer_Init file.size, file.tell #Inform MediaInfo we have seek
101+
end
102+
else
103+
break
104+
end
105+
end
106+
107+
puts ""
108+
puts "Open_Buffer_Finalize"
109+
mi.Open_Buffer_Finalize
110+
111+
puts ""
112+
puts "Get with Stream=General and Parameter='Format'"
113+
puts mi.Get :General, 0, "Format"
114+
end

0 commit comments

Comments
 (0)