protected virtual async Task <Stream> OpenStreamAsync(string assetName) { Stream stream; try { var assetPath = Path.Combine(RootDirectory, assetName) + ".xnb"; // This is primarily for editor support. // Setting the RootDirectory to an absolute path is useful in editor // situations, but TitleContainer can ONLY be passed relative paths. #if DESKTOPGL || WINDOWS if (Path.IsPathRooted(assetPath)) { stream = File.OpenRead(assetPath); } else #endif stream = await TitleContainer.OpenStreamAsync(assetPath); #if ANDROID // Read the asset into memory in one go. This results in a ~50% reduction // in load times on Android due to slow Android asset streams. MemoryStream memStream = new MemoryStream(); stream.CopyTo(memStream); memStream.Seek(0, SeekOrigin.Begin); stream.Close(); stream = memStream; #endif } #if !WEB catch (FileNotFoundException fileNotFound) { throw new ContentLoadException("The content file was not found.", fileNotFound); } #if !WINDOWS_UAP catch (DirectoryNotFoundException directoryNotFound) { throw new ContentLoadException("The directory was not found.", directoryNotFound); } #endif #endif catch (Exception exception) { throw new ContentLoadException("Opening stream error.", exception); } return(stream); }