is there a way to force loading a StorageFile in memory?

John Torjo 861 Reputation points
2020-02-24T09:53:06.93+00:00

I have a StorageFile that I want to use as input for a Media Composition (as a Media Clip).

I'm hoping loading everything in memory, to speed things up. I don't know how to do this - is there any way to do it?

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Richard Zhang-MSFT 6,936 Reputation points
    2020-02-25T02:12:09.333+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    The MediaClip.CreateFromFileAsync method accepts a parameter type of IStorageFile, which means you need to pass in a variable of type StorageFile.

    Although we can use a MemoryStream to save a file stream in memory, MediaClip doesn't have a method of CreateFromStreamAsync, so in your case you can only load data from the file.

    ---

    If you are establishing a connection between MediaClip and Stream, you can use StorageFile.ReplaceWithStreamedFileAsync as a relay.

    You can first read the StorageFile as a Stream, then use this method to convert the Stream to a StorageFile when needed, and pass it to MediaClip.

    However, it should be noted that loading the file into memory has no effect on the speed of MediaComposition.

    Thanks.


1 additional answer

Sort by: Most helpful
  1. macintoshpro 36 Reputation points
    2020-02-24T15:39:50.577+00:00

    Of couse, you can read StorageFile as a stream (stream is in memory)