一点背景。我希望能够通过javascript以编程方式控制Amazon Instant Video上的Silverlight视频播放器。
使用开发者控制台。我在DOM中找到了视频播放器元素。
<div id="player_container" style="display: block;">
<object type="application/x-silverlight"
data="data:application/x-silverlight,"
id="player_object"
width="50%"
height="100%">
<param name="color" value="#ffffff">
<param name="background" value="#000000">
<param name="minRuntimeVersion" value="5.1">
<param name="autoUpgrade" value="false">
... elided several <param>'s here ...
</object>
</div>
然后我在开发者控制台的js repl中输入以下内容:
> var silver = document.getElementById("player_object");
然后我尝试关注instructions found here。我应该采取哪种状态,
> silver.content.findName(SOMETHING_HERE);
我不确定SOMETHING_HERE用什么,所以我用
下载了silverlight应用程序wget http://www.amazon.com/gp/video/streaming/silverlightPlayer.xap?ie=UTF8&version=104.0-0
unzip silverlightPlayer.xap?ie=UTF8
然后我查看解压缩的AppManifest.xaml:
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ExternalCallersFromCrossDomain="ScriptableOnly" EntryPointAssembly="Amazon.ATVSilverlightPlayer" EntryPointType="Amazon.ATVSilverlightWebPlayer.App" RuntimeVersion="5.0.61118.0">
<Deployment.Parts>
<AssemblyPart x:Name="Amazon.ATVSilverlightPlayer" Source="Amazon.ATVSilverlightPlayer.dll" />
<AssemblyPart x:Name="Amazon.AIV.Utilities" Source="Amazon.AIV.Utilities.dll" />
<AssemblyPart x:Name="Amazon.Common" Source="Amazon.Common.dll" />
<AssemblyPart x:Name="AmazonPlayer.Themes.DarkGray" Source="AmazonPlayer.Themes.DarkGray.dll" />
<AssemblyPart x:Name="AtvAdsManager" Source="AtvAdsManager.dll" />
<AssemblyPart x:Name="ATVQos" Source="ATVQos.dll" />
<AssemblyPart x:Name="Microsoft.Logging.LocalConnection" Source="Microsoft.Logging.LocalConnection.dll" />
<AssemblyPart x:Name="Microsoft.SilverlightMediaFramework.Core" Source="Microsoft.SilverlightMediaFramework.Core.dll" />
<AssemblyPart x:Name="Microsoft.SilverlightMediaFramework.Diagnostics" Source="Microsoft.SilverlightMediaFramework.Diagnostics.dll" />
<AssemblyPart x:Name="Microsoft.SilverlightMediaFramework.Logging" Source="Microsoft.SilverlightMediaFramework.Logging.dll" />
<AssemblyPart x:Name="Microsoft.SilverlightMediaFramework.Plugins" Source="Microsoft.SilverlightMediaFramework.Plugins.dll" />
<AssemblyPart x:Name="Microsoft.SilverlightMediaFramework.Plugins.Monitoring" Source="Microsoft.SilverlightMediaFramework.Plugins.Monitoring.dll" />
<AssemblyPart x:Name="Microsoft.SilverlightMediaFramework.Plugins.Progressive" Source="Microsoft.SilverlightMediaFramework.Plugins.Progressive.dll" />
<AssemblyPart x:Name="Microsoft.SilverlightMediaFramework.Plugins.SmoothStreaming" Source="Microsoft.SilverlightMediaFramework.Plugins.SmoothStreaming.dll" />
<AssemblyPart x:Name="Microsoft.SilverlightMediaFramework.Plugins.TimedText" Source="Microsoft.SilverlightMediaFramework.Plugins.TimedText.dll" />
<AssemblyPart x:Name="Microsoft.SilverlightMediaFramework.Utilities" Source="Microsoft.SilverlightMediaFramework.Utilities.dll" />
<AssemblyPart x:Name="Microsoft.Web.Media.SmoothStreaming" Source="Microsoft.Web.Media.SmoothStreaming.dll" />
<AssemblyPart x:Name="Newtonsoft.Json" Source="Newtonsoft.Json.dll" />
<AssemblyPart x:Name="System.Json" Source="System.Json.dll" />
<AssemblyPart x:Name="System.Xml.Linq" Source="System.Xml.Linq.dll" />
<AssemblyPart x:Name="System.ComponentModel.Composition" Source="System.ComponentModel.Composition.dll" />
<AssemblyPart x:Name="System.Xml.Serialization" Source="System.Xml.Serialization.dll" />
<AssemblyPart x:Name="System.ComponentModel.Composition.Initialization" Source="System.ComponentModel.Composition.Initialization.dll" />
<AssemblyPart Source="de/Amazon.ATVSilverlightPlayer.resources.dll" />
<AssemblyPart Source="en-GB/Amazon.ATVSilverlightPlayer.resources.dll" />
<AssemblyPart Source="ja/Amazon.ATVSilverlightPlayer.resources.dll" />
<AssemblyPart Source="de/System.Json.resources.dll" />
<AssemblyPart Source="ja/System.Json.resources.dll" />
<AssemblyPart Source="de/System.Xml.Linq.resources.dll" />
<AssemblyPart Source="ja/System.Xml.Linq.resources.dll" />
<AssemblyPart Source="de/System.ComponentModel.Composition.resources.dll" />
<AssemblyPart Source="ja/System.ComponentModel.Composition.resources.dll" />
<AssemblyPart Source="de/System.Xml.Serialization.resources.dll" />
<AssemblyPart Source="ja/System.Xml.Serialization.resources.dll" />
<AssemblyPart Source="de/System.ComponentModel.Composition.Initialization.resources.dll" />
<AssemblyPart Source="ja/System.ComponentModel.Composition.Initialization.resources.dll" />
</Deployment.Parts>
</Deployment>
在使用x:Name
时,我尝试用。SOMETHING_HERE
替换.xaml文件中的许多silver.content.findName(SOMETHING_HERE)
值。始终返回null。我想得到一个句柄,让我从我自己的JavaScript控制台播放/暂停/寻找亚马逊即时视频?我该怎么办?
答案 0 :(得分:1)
应用清单不是实际的Silverlight应用程序,它定义xap文件中的哪些程序集构成Silverlight应用程序。您尝试访问的Silverlight MediaElement是在应用程序清单中列出的某个dll中包含的xaml文件中定义的,Amazon.ATVSilverlightPlayer.dll是我开始查找的地方。我喜欢.NET Reflector来检查dll。
按名称引用MediaElement是一种脆弱的方法,因为为Silverlight元素分配x:name属性是可选的,Amazon可以随时更改它。您可以按照此处描述的方法遍历Silverlight应用程序可视树并查找MediaElement类型的对象:Javascript array of TextBlock elements from Xaml file
我必须稍微改一下才能让它适合我:
var hasLoaded = false;
function onSilverlightLoad(sender) {
if (hasLoaded) {
return;
}
forEachDescendant(document.getElementById('silverlightObject').content.Root);
hasLoaded = true;
}
function forEachDescendant(elem) {
if (elem != null) {
console.log('Type: ' + elem.toString());
if (typeof elem.children == 'object') {
for (var i = 0; i < elem.children.count; i++) {
var child = elem.children.getItem(i);
forEachDescendant(child);
}
}
else if (typeof elem.content == 'object') {
forEachDescendant(elem.content);
}
}
}