silverlight3如何播放DRM加密的视频
以下microsoft的例子代码,调不通,请高人指点下.
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
// Test a full fledged manual acquirer
// Set the LicenseAcquirer of the MediaElement to the custom License Aquirer
// defined in this sample.
myME.LicenseAcquirer = new ManualLicenseAcquirer(myME.Name);
// Set the License URI to proper License Server address.
myME.LicenseAcquirer.LicenseServerUriOverride = new Uri("http://contoso.com/myLicenseServer.asmx", UriKind.Absolute);
myME.MediaFailed += new EventHandler<ExceptionRoutedEventArgs>(myME_MediaFailed);
// Set the source of the MediaElement to the URL of the media encrypted with WMDRM.
myME.Source = new Uri("http://contoso.com/wmdrm_url.wmv", UriKind.Absolute);
}
void myME_MediaFailed(object sender, ExceptionRoutedEventArgs e)
{
System.Windows.Browser.HtmlPage.Window.Alert("MediaFailed: " + e.ErrorException.Message + ".");
}
// makes license request explicitly
public class ManualLicenseAcquirer : LicenseAcquirer
{
private string challengeString;
string _mediaElementName;
public ManualLicenseAcquirer(string mediaElementName)
{
_mediaElementName = mediaElementName;
}
// The default implementation of OnAcquireLicense calls into the MediaElement to acquire a
// license. It is called when the Media pipeline is building a topology and will be raised
// before MediaOpened is raised.
protected override void OnAcquireLicense(System.IO.Stream licenseChallenge, Uri licenseServerUri)
{
StreamReader sr = new StreamReader(licenseChallenge);
challengeString = sr.ReadToEnd();
// Need to resolve the URI for the License Server -- make sure it is correct
// and store that correct URI as resolvedLicenseServerUri.
Uri resolvedLicenseServerUri;
if (LicenseServerUriOverride == null)
resolvedLicenseServerUri = licenseServerUri;
else
resolvedLicenseServerUri = LicenseServerUriOverride;
// Make a HttpWebRequest to the License Server.
HttpWebRequest request = WebRequest.Create(resolvedLicenseServerUri) as HttpWebRequest;
request.Method = "POST";
// Set ContentType through property
request.ContentType = "application/xml";
// ADD REQUIRED HEADERS.
// The headers below are necessary so that error handling and redirects are handled
// properly via the Silverlight client.
request.Headers["msprdrm_server_redirect_compat"] = "false";
request.Headers["msprdrm_server_exception_compat"] = "false";
// Initiate getting request stream
IAsyncResult asyncResult = request.BeginGetRequestStream(new AsyncCallback(RequestStreamCallback), request);
}
// This method is called when the asyncrhonous operation completes.
void RequestStreamCallback(IAsyncResult ar)
{
HttpWebRequest request = ar.AsyncState as HttpWebRequest;
// populate request stream
request.ContentType = "text/xml";
Stream requestStream = request.EndGetRequestStream(ar);
StreamWriter streamWriter = new StreamWriter(requestStream, System.Text.Encoding.UTF8);
streamWriter.Write(challengeString);
streamWriter.Close();
// Make async call for response
request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);
}
private void ResponseCallback(IAsyncResult ar)
{
HttpWebRequest request = ar.AsyncState as HttpWebRequest;
WebResponse response = request.EndGetResponse(ar);
SetLicenseResponse(response.GetResponseStream());
}
}
}