Reputation: 14524
A little bit of context. I want to be able to programmatically control the Silverlight video player on Amazon Instant Video from javascript.
Using the developer console. I have found the video player element in the 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>
I then enter the following in the js repl in the developer console:
> var silver = document.getElementById("player_object");
I am then attempting to follow the instructions found here. Which state that I should,
> silver.content.findName(SOMETHING_HERE);
I am unsure what to use for SOMETHING_HERE, so I downloaded the silverlight app with
wget http://www.amazon.com/gp/video/streaming/silverlightPlayer.xap?ie=UTF8&version=104.0-0
unzip silverlightPlayer.xap?ie=UTF8
I then look in the unzipped 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>
I have tried substituting many of the x:Name
values found in the .xaml file for SOMETHING_HERE
when using silver.content.findName(SOMETHING_HERE)
. Always returns null. I want to get a handle that lets me play/pause/seek amazon instant video from my own javascript console? How should I procceed?
Upvotes: 1
Views: 534
Reputation: 6629
The app manifest is not the actual Silverlight application, it defines what assemblies in the xap file make up the Silverlight application. The Silverlight MediaElement you are trying to access is defined in a xaml file contained in one of the dll's listed in the app manifest, Amazon.ATVSilverlightPlayer.dll is where I would start looking. I like .NET Reflector for inspecting dlls.
Referencing the MediaElement by name is a fragile approach as assigning a x:name attribute to Silverlight elements is optional and Amazon could change it at any point. You could traverse the Silverlight app visual tree and look for objects of a type MediaElement by following an approach described here: Javascript array of TextBlock elements from Xaml file
I had to change it slightly to get it working for me:
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);
}
}
}
Upvotes: 1