99
1010#region Using Statements
1111using System ;
12+ using System . Collections . Generic ;
1213using System . IO ;
13-
1414using Microsoft . Xna . Framework . Graphics ;
1515#endregion
1616
@@ -61,6 +61,12 @@ internal GraphicsDevice GraphicsDevice
6161 private set ;
6262 }
6363
64+ internal String Codec
65+ {
66+ get ;
67+ private set ;
68+ }
69+
6470 #endregion
6571
6672 #region Internal Variables
@@ -86,24 +92,11 @@ internal Video(string fileName, GraphicsDevice device)
8692 throw new FileNotFoundException ( fileName ) ;
8793 }
8894
89- IntPtr theora ;
90- int width ;
91- int height ;
92- double fps ;
93- Theorafile . th_pixel_fmt fmt ;
94- Theorafile . tf_fopen ( fileName , out theora ) ;
95- Theorafile . tf_videoinfo (
96- theora ,
97- out width ,
98- out height ,
99- out fps ,
100- out fmt
101- ) ;
102- Theorafile . tf_close ( ref theora ) ;
103-
104- Width = width ;
105- Height = height ;
106- FramesPerSecond = ( float ) fps ;
95+ Codec = GuessCodec ( fileName ) ;
96+ VideoPlayer . VideoInfo info = VideoPlayer . codecInfoReaders [ Codec ] ( fileName ) ;
97+ Width = info . width ;
98+ Height = info . height ;
99+ FramesPerSecond = ( float ) info . fps ;
107100
108101 // FIXME: This is a part of the Duration hack!
109102 Duration = TimeSpan . MaxValue ;
@@ -118,6 +111,18 @@ internal Video(
118111 int height ,
119112 float framesPerSecond ,
120113 VideoSoundtrackType soundtrackType
114+ ) : this ( fileName , device , durationMS , width , height , framesPerSecond , soundtrackType , GuessCodec ( fileName ) ) {
115+ }
116+
117+ internal Video (
118+ string fileName ,
119+ GraphicsDevice device ,
120+ int durationMS ,
121+ int width ,
122+ int height ,
123+ float framesPerSecond ,
124+ VideoSoundtrackType soundtrackType ,
125+ string codec
121126 ) {
122127 handle = fileName ;
123128 GraphicsDevice = device ;
@@ -130,6 +135,7 @@ VideoSoundtrackType soundtrackType
130135 Width = width ;
131136 Height = height ;
132137 FramesPerSecond = framesPerSecond ;
138+ Codec = codec ;
133139
134140 // FIXME: Oh, hey! I wish we had this info in Theora!
135141 Duration = TimeSpan . FromMilliseconds ( durationMS ) ;
@@ -141,7 +147,7 @@ VideoSoundtrackType soundtrackType
141147 #endregion
142148
143149 #region Public Extensions
144-
150+
145151 public static Video FromUriEXT ( Uri uri , GraphicsDevice graphicsDevice )
146152 {
147153 string path ;
@@ -169,7 +175,7 @@ public static Video FromUriEXT(Uri uri, GraphicsDevice graphicsDevice)
169175
170176 internal int audioTrack = - 1 ;
171177 internal int videoTrack = - 1 ;
172- internal VideoPlayer parent ;
178+ internal IVideoPlayerImpl parent ;
173179
174180 public void SetAudioTrackEXT ( int track )
175181 {
@@ -190,5 +196,24 @@ public void SetVideoTrackEXT(int track)
190196 }
191197
192198 #endregion
199+
200+ #region Private Static Methods
201+
202+ private static string GuessCodec ( String filename )
203+ {
204+ filename = filename . ToLower ( ) ;
205+ foreach ( KeyValuePair < string , string > kvp in VideoPlayer . codecExtensions )
206+ {
207+ if ( filename . EndsWith ( kvp . Key ) )
208+ {
209+ return kvp . Value ;
210+ }
211+ }
212+
213+ // For backwards compatibility
214+ return "Theora" ;
215+ }
216+
217+ #endregion
193218 }
194219}
0 commit comments