Skip to content Skip to sidebar Skip to footer

How Do I Pause/play/seek A Silverlight Video Using Javascript

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 fo

Solution 1:

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;

    functiononSilverlightLoad(sender) {
        if (hasLoaded) {
            return;
        }
        forEachDescendant(document.getElementById('silverlightObject').content.Root);
        hasLoaded = true;
    }

    functionforEachDescendant(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);
                }
            }
            elseif (typeof elem.content == 'object') {
                forEachDescendant(elem.content);
            }
        }
    }

Post a Comment for "How Do I Pause/play/seek A Silverlight Video Using Javascript"