问题
On WP7 platform (using C# and Silverlight) I try to play an online stream into a MediaElement...
Here is the C# code: (...)
WebClient wc = new WebClient();
wc.OpenReadCompleted += (s, e) =>
{
try
{
mediaElement.SetSource(e.Result);
}
catch (Exception we)
{
System.Diagnostics.Debug.WriteLine(we.Message);
}
};
wc.OpenReadAsync(new Uri(url, UriKind.Absolute));
(...) Here is the XAML source code:
<MediaElement Height="316" HorizontalAlignment="Left" Margin="6,6,0,0" Name="mediaElement" VerticalAlignment="Top" Width="450" AutoPlay="False" /
>
The url is type of http://.../Manifest and the format is a one supported by the platform.
When SetSource is called then an exception is raised with the following message "Stream must be of type IsolatedStorageFileStream".
What do I do wrong?
Thanks in advance for some help Cheers
回答1:
MSDN says:
Passing a generic stream to SetSource(System.IO.Stream) is not supported in Silverlight for Windows Phone. However, the IsolatedStorageFileStream class, which derives from Stream, is suppoted on Silverlight for Windows Phone.
Instead, consider setting the MediaElement.Source property directly to the stream uri. There's no reason to "download" it first.
来源:https://stackoverflow.com/questions/7511851/windows-phone-7-playing-streaming-video