locked
MEPlaybackNative Sample, with GetFileFromPathAsync

    Question

  • Hello,

    I'm trying to implement the MEPlaybackNative sample that came with the Consumer Preview Samples, without the use of the file picked. I'd like to just be able to specify a file path on my local machine and have it play that video instead of bringing up the file picker.

    The method I'm currently trying to implement is to use StorageFile::GetFileFromPathAsync(). In the following manner:

    m_pickFileTask = task<StorageFile^>(StorageFile::GetFileFromPathAsync("temp.mp4"), m_tcs.get_token());

    I've just replaced. Line 420's "getVidFile->PickSingleFileAsync()" with the "StorageFile::GetFileFromPathAsync( "temp.mp4" )". I have the temp.mp4 file added into the project so I don't think that would be an issue, and when it builds it's built in as content.

    At the moment, this doesn't work as it just runs the application and stays as a blank screen. Without even going into the try catch block below.

    This is the method I'm using, if someone has a different method then I'd be willing to use that instead.

    I would appreciate any help anyone can provide me with on this issue.

    Thanks!


    • Edited by DLAlex Friday, April 20, 2012 3:08 PM
    Friday, April 20, 2012 3:07 PM

Answers

  • Hey Everyone.

    I've done some more research into it and finally found information that GetFileFromPathAsync doesn't take a relative path. So a work around that I've figured out is to do this:

    StorageFolder^ installedLocation = Windows::ApplicationModel::Package::Current->InstalledLocation;
    m_pickFileTask = task<StorageFile^>(installedLocation->GetFileAsync("temp.mp4"), m_tcs.get_token());

    The installed location is a predefined variable that you don't have to initialize. Just set a new StorageFolder to it and call GetFileAsync() instead with your relative path. This also works if you have subfolders in your installed location that you're looking for files in.

    Big thanks to this blog: http://blogs.msdn.com/b/avip/archive/2011/09/19/windows-8-development-tip-packaging-and-loading-files.aspx I found the information needed here.

    Hope this helps some other people as well!

    • Marked as answer by DLAlex Friday, April 20, 2012 4:04 PM
    Friday, April 20, 2012 4:04 PM

All replies

  • Hey Everyone.

    I've done some more research into it and finally found information that GetFileFromPathAsync doesn't take a relative path. So a work around that I've figured out is to do this:

    StorageFolder^ installedLocation = Windows::ApplicationModel::Package::Current->InstalledLocation;
    m_pickFileTask = task<StorageFile^>(installedLocation->GetFileAsync("temp.mp4"), m_tcs.get_token());

    The installed location is a predefined variable that you don't have to initialize. Just set a new StorageFolder to it and call GetFileAsync() instead with your relative path. This also works if you have subfolders in your installed location that you're looking for files in.

    Big thanks to this blog: http://blogs.msdn.com/b/avip/archive/2011/09/19/windows-8-development-tip-packaging-and-loading-files.aspx I found the information needed here.

    Hope this helps some other people as well!

    • Marked as answer by DLAlex Friday, April 20, 2012 4:04 PM
    Friday, April 20, 2012 4:04 PM
  • Thanks for sharing the solution.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 23, 2012 2:29 AM