1
votes

I'm trying to make some wp7 app which should play videos from server. One of the app's features is downloading selected videos and playing them from isolated storage.

I'm using next code for downloading:

WebClient wc = new WebClient();
wc.OpenReadCompleted += (s, a) => { /* saving result stream to isolated storage */}
wc.OpenReadAsync(fileUri);

So, when I click on play button, I check if file was downloaded or not, and if it was I open IsolatedStorageFileStream for this file and set it to player's source, otherwise I set to source file Uri.

Problem is that I get MediaFailed exception when I'm trying to set IsolatedStorageFileStream as MedialElement's source. Can anybody help me with it?

Code looks like in next way

private IsolatedStorageFile isf;
private IsolatedStorageFileStream stream;

private void playButton_Click(..)
{
isf = IsolatedStorageFile.GetUserStoreForApplication();
stream = isf.OpenFile(path, FileMode.Open);
MediaPlayer.SetSource(stream);
MediaPlayer.Play();
}

Stream is not corrupted, its length is correct. I realy don't know what to do with it. Thanks in advance

2
Not a solution to your problem, but once you get over this issue watch out: in non-WP Silverlight there is a bug that makes reading the IsolatedStorage from a non-UI thread very slow (and would sure impact your scenario). It's possible that in WP7 there is the same problemFrancesco De Vittori

2 Answers

2
votes

I've found solution, it's very strange, but works

The problem was that I save files with names %clipId%.clip, but when I changed file names to %clipId%.mp4 (my clips are encoded in mp4) it becomes work!!!

Can't understand why it is so.

2
votes

The media player looks at the filename to check if it supports the format. ".clip" is no valid format.