2121#region Using Statements
2222using System ;
2323using System . IO ;
24-
24+ using Microsoft . Xna . Framework . Media ;
2525using SDL3 ;
2626#endregion
2727
@@ -36,7 +36,12 @@ public static Stream OpenStream(string name)
3636 string safeName = MonoGame . Utilities . FileHelpers . NormalizeFilePathSeparators ( name ) ;
3737
3838 if ( SDL . SDL_GetPlatform ( ) == "Android" )
39+ {
40+ if ( IsSongOrVideo ( safeName ) )
41+ return AndroidExtractAssetAndOpenStream ( safeName ) ;
42+
3943 return new SDL3IOStream ( safeName ) ;
44+ }
4045
4146#if CASE_SENSITIVITY_HACK
4247 if ( Path . IsPathRooted ( safeName ) )
@@ -146,6 +151,44 @@ private static string SearchCase(string name, string[] list)
146151#endif
147152
148153 #endregion
154+
155+ internal static bool IsSongOrVideo ( string name )
156+ {
157+ string ext = Path . GetExtension ( name ) . ToLower ( ) ;
158+ for ( int i = 0 ; i < Content . SongReader . supportedExtensions . Length ; i += 1 )
159+ {
160+ if ( ext == Content . SongReader . supportedExtensions [ i ] )
161+ return true ;
162+ }
163+ for ( int i = 0 ; i < Content . VideoReader . supportedExtensions . Length ; i += 1 )
164+ {
165+ if ( ext == Content . VideoReader . supportedExtensions [ i ] )
166+ return true ;
167+ }
168+ foreach ( var item in VideoPlayer . codecExtensions )
169+ {
170+ if ( ext == "." + item . Key )
171+ return true ;
172+ }
173+ return false ;
174+ }
175+
176+ public static FileStream AndroidExtractAssetAndOpenStream ( string name )
177+ {
178+ var path = Path . Combine ( TitleLocation . Path , name ) ;
179+ if ( ! File . Exists ( path ) )
180+ {
181+ var inputStream = new SDL3IOStream ( name ) ;
182+
183+ Directory . CreateDirectory ( Path . GetDirectoryName ( path ) ) ; // Ensure subdirectories
184+ FileStream s = new FileStream ( path , FileMode . OpenOrCreate , FileAccess . ReadWrite ) ;
185+ inputStream . CopyTo ( s ) ;
186+ s . Seek ( 0 , SeekOrigin . Begin ) ;
187+ return s ;
188+ }
189+ else
190+ return File . OpenRead ( path ) ;
191+ }
149192 }
150193}
151194
0 commit comments