Is there a Javascript API for the Netflix Instant player (silverlight)? Preferably a supported, documented one, but an unsupported, undocumented one might be okay too; this is for a personal project.
I'd like to be able to play/pause and seek to a given time.
I had fun digging into this, and I think I found your answer.
To start, I found an (admittedly old) post from someone at Netflix stating that their licensing requirements prohibited them from providing ways to control the player externally (everything needed to be wrapped up in a netflix-branded application, and providing ways to interact with the player externally would allow you to embed the netflix player in places it shouldn't go.) You can find that reply here (although it's four years old, I'd imagine not much has changed.)
http://developer.netflix.com/forum/read/54172
I tried snooping around on the 'watch instantly' page myself, and there are objects like netflix.SilverLight and netflix.SilverLight.MoviePlayer (which has a getPlugin() method that returns some details about the plugin, and hookable events, but no methods for control,) but they mostly have to do with exposing the size of the player viewport, among other things necessary to place it on the page. I couldn't really find anything in any of the objects that suggested they interacted with the movie player that would seem to allow me access to it.
I also snagged the player binaries, and snooping through them I've found a ScriptInterface object internally with [ScriptableMember]-decorated methods in it called PlayMovie(), StopMovie(), ShowCurtain(), HideCurtain().
Then, I noticed there's another namespace in the player binaries called Netflix.Silverlight.CBPApp.HostedPlayer, which has its own interface - HostedPlayerScriptInterface. This has everything you want in it - data on play position, controls for increasing and decreasing play speed, pausing, playing, setting the play position, querying play state, etc. All of these are decorated as [ScriptableMember]s.
Now I break your heart - it looks like (for whatever reason) this interface is not exposed as a [ScriptableType], which to my understanding is a requirement for being able to access it from javascript. In fact, the only things that seem to be exposed this way are events that the player fires. My guess is that this code is for integrating with other partners, or left over from someone they inherited the original code for the video player from, but it seems intentionally that this [ScriptableType] parameter is left out. There may be a way to request a binary that's built to be 'Hosted', though I'm not sure what that means, and I also suspect it will be transparently obvious to the people watching what you're trying to do and have a stop put to it quickly.
Sorry for the long-winded response that ends in disappointment, but it appears as of right now there's not really a way to do this. I've seen some suggestions that basically amount to sending keystrokes to the browser window that emulate the keyboard controls, but this clearly isn't what you're looking for, so I'm going to go with 'no' as an answer here. :)
Edit:
Further research is showing this is not the dead end that I thought it was. I'll update this once I'm done digging.
Edit 2:
So, looks like you need to trick the Netflix player into thinking it's running in hosted player mode. There's some configuration options that can be passed in, but I'm not sure how, specifically, you would do that. It looks like that's all set up on player initialization - maybe some sort of bookmarklet could reload the page and inject a change? Or maybe just reload the player and change the settings.
this.PlayerViewModel = (applicationConfiguration.PlayerConfiguration.EnableHostedPlayerControl ? new HostedPlayerViewModel() : new GenesisPlayerViewModel());
Is where I figured that out. When the HostedPlayerViewModel is used, this code gets run:
HtmlPage.RegisterScriptableObject("HostedPlayerControlScriptInterface_1", this.b)
which if I'm reading correctly will let you access this registered object by getting the DOM object containing the netflix silverlight player and calling
silverlightPlayer.content.findName('HostedPlayerControlScriptInterface_1').WhateverMethod()
Bear in mind I haven't done much of this javascript interop stuff so much of this is inferred from the documentation, but it does seem as if there is a javascript control API in there, it's just a matter of tricking the player into working in Hosted mode.
Going to have to stop here, but hopefully this gives you a good start. I've dumped the contents of that hosted player Javascript API file so you can see the methods that will be exposed once you manage to get the player in Hosted mode.
http://pastebin.com/UeN3NFMg
Good luck!
I'm way late to the party and I'm sure much has changed to how netflix handles it's clientside code, but I suggest you look at the object returned by netflix.cadmium.objects.videoPlayer()
.
This will change eventually but hey it might be useful.
Since you mentioned undocumented...
In Silverlight for a method to be exposed to JavaScript directly, it needs attributes [ScriptableType]
on its class and [ScriptableMember]
on itself. You could try opening up the XAP file for the Netflix player, disassembling the main assembly, and searching for any methods with [ScriptableMember]
attached to them. This may not turn up anything useful at all, but it is something you can try nonetheless.
Perhaps the Netflix official webpage is a place to start looking?
http://developer.netflix.com/docs/JavaScript_APIs
Boxee might have been able to control it at some point: http://dir.boxee.tv/apps/helper2/netflix.js
(a few other forks of that may be around as well).
I also wonder if netflix transferring to an HTML5 implementation would somehow allow a plugin to control playback. GL!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With