locked
How to set source of MediaElement?

    Question

  • How to set a file path by Uri to the source of a MediaElement?

    My code:

    StorageFile^ pFile;

    VideoPlayer->Source = ref new Uri("file://"+pFile->Path);

    ----------------------------------------------------------

    I don't want to open the file and call SetSource.

    Any one can help me?

    Thank you.


    • Edited by ytshe Wednesday, July 18, 2012 2:58 AM
    Wednesday, July 18, 2012 1:46 AM

Answers

  • What is the path you are trying to open?

    Your code looks correct so long as the file is in a location that your app can natively read. If the file is outside of your installed directory or app data folder then your app doesn't have permission to read the file directly but needs to have the StorageFile read it for you. In that case, opening the StorageFile and calling SetSource is the only option.

    --Rob

    • Marked as answer by ytshe Wednesday, July 18, 2012 9:36 AM
    Wednesday, July 18, 2012 5:11 AM
    Owner

All replies

  • What is the path you are trying to open?

    Your code looks correct so long as the file is in a location that your app can natively read. If the file is outside of your installed directory or app data folder then your app doesn't have permission to read the file directly but needs to have the StorageFile read it for you. In that case, opening the StorageFile and calling SetSource is the only option.

    --Rob

    • Marked as answer by ytshe Wednesday, July 18, 2012 9:36 AM
    Wednesday, July 18, 2012 5:11 AM
    Owner
  • Rob:

    Thanks, I know.

    I got the file by file picker, may be is was caused by ' doesn't have permission'.

    Wednesday, July 18, 2012 9:37 AM