silverlight3如何播放DRM加密的视频

will97 2010-03-17 02:49:41
以下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());
}
}
}
...全文
914 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jv9 2010-03-20
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 will97 的回复:]
http://contoso.com/myLicenseServer.asmx -> http://xxx.xxx.xxx.xxx:xxxx/xxx.aspx
http://contoso.com/wmdrm_url.wmv -> http://xxx.xxx.xxx.xxx:xxxx/xxx.wmv
以上两句已经改为相应内容:
[/Quote]

以上两个链接单独访问都正常么?试着使用Fiddler抓取Http包看看,Http反馈错误是什么?
will97 2010-03-19
  • 打赏
  • 举报
回复
http://contoso.com/myLicenseServer.asmx -> http://xxx.xxx.xxx.xxx:xxxx/xxx.aspx
http://contoso.com/wmdrm_url.wmv -> http://xxx.xxx.xxx.xxx:xxxx/xxx.wmv
以上两句已经改为相应内容:

jv9 2010-03-19
  • 打赏
  • 举报
回复
调试资源字符串不可用。密钥和参数通常提供足够的信息用以诊断该问题。

http://contoso.com/myLicenseServer.asmx

http://contoso.com/wmdrm_url.wmv

都不能访问使用。所以返回资源调用失败错误。
omore 2010-03-18
  • 打赏
  • 举报
回复
学一下
xiaoniao2007 2010-03-18
  • 打赏
  • 举报
回复
学习中~!
will97 2010-03-18
  • 打赏
  • 举报
回复
这句报的错:WebResponse response = request.EndGetResponse(ar);
报错内容:
消息: Unhandled Error in Silverlight Application [HttpWebRequest_WebException_RemoteServer]
参数:NotFound
调试资源字符串不可用。密钥和参数通常提供足够的信息用以诊断该问题。请访问 http://go.microsoft.com/fwlink/?linkid=106663&Version=3.0.50106.0&File=System.Windows.dll&Key=HttpWebRequest_WebException_RemoteServer 位于 System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
位于 System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
位于 StuVideoPlatfrom.Media_DRM.ManualLicenseAcquirer.ResponseCallback(IAsyncResult ar)
位于 System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassd.<InvokeGetResponseCallback>b__b(Object state2)
位于 System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
位于 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
位于 System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
位于 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
行: 1
字符: 1
代码: 0
URI: http://192.168.1.188:9166/StuVideoPlatfromTestPage.aspx

且错误说明页不可访问:
http://go.microsoft.com/fwlink/?linkid=106663&Version=3.0.50106.0&File=System.Windows.dll&Key=HttpWebRequest_WebException_RemoteServer
will97 2010-03-18
  • 打赏
  • 举报
回复
还没人回答?顶一下也好!
jv9 2010-03-17
  • 打赏
  • 举报
回复
这样单独看代码文件很难判断问题出现哪里,能说一下什么报错信息么?这样可以集中看报错代码段。

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧