I’m working on a sound recorder app for Windows 8, and have noticed that when I pass a IRandomAccessStream to MediaElement.SetSource, the application crashes, and no exception is thrown that is visible to Visual Studio. How should I debug this issue? What could be causing it?
Here is the code that is causing the crash:
void mediaFiles_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
{
string fname = e.AddedItems[0] as string;
Stream fstream = GlobalVariables.encryptedFS.OpenFile(fname);
MediaElement elem = new MediaElement();
mainGrid.Children.Add(elem);
elem.AutoPlay = true;
elem.SetSource(new WinRTStream(fstream, true), "audio/x-ms-wma");
}
}
Fixed it. Turned out to be a bug in my implementation of IAsyncOperationWithProgress.
For those facing similar difficulties, here’s the code that fixed it: