Help needed develpoing BrowserSiteUtil (1 Viewer)

Dj_Moren

Portal Pro
November 7, 2009
171
25
Hello,

I'm trying to create a new site util which uses the BrowserPlayer because it is developed with Silverlight. I think that nowadays this is the only possible approach for this kind of sites. I have implemented some custom site utils without problem, but with this kind I'm a bit confused. I have copy&pasted Netflix site util and started doing changes to do simple tests to see if this could work. I'm having 2 big problems:
1. I'm unable to debug the connector class, neither with breakpoints nor with debug logs. How can I do this?
2. I'm trying to guess how does the complete lifecycle of a Connector work and I'm still unable. Could be possible to read a little post with any kind of documentation/explanation about this?

Thank you.

PS: I'm going to mention @Ministerk because I think he could help the community resolving this problems. Thank you.
 

Ministerk

Super User
  • Team MediaPortal
  • Super User
  • November 28, 2007
    970
    826
    Uppsala
    Home Country
    Sweden Sweden
    Some quick answers (a lot of trail and error has be put into this...)

    1. I'm unable to debug the connector class, neither with breakpoints nor with debug logs. How can I do this?
    The easy part first...
    Log: Use MessageHandler from BrowserUtilConnector class to log but you also have to configure the browser player to write to log. Do this by changing OnlineVideos.WebAutomation.BrowserHost.exe.config file (found in [MP-INSTALL-PATH]l\plugins\Windows\OnlineVideos) Change the WriteDebugLog value to true. This will change every time you compile the Mediaportal1 project (or OnlineVideos.WebAutomation.BrowserHost). So edit the App.config in OnlineVideos.WebAutomation.BrowserHost instead and rebuild.

    You can debug the connector by attaching to the OnlineVideos.WebAutomation.BrowserHost.exe Process. But you have to be fast... Or delaying the process by
    Code:
    //in BrowserDocumentComplete
    Thread.Sleep(5000);
    //Or maybe some thread blocking js:
    InvokeScript("alert('debug please...');");
    Place your breakpoint after the thread delay.

    2. I'm trying to guess how does the complete lifecycle of a Connector work and I'm still unable. Could be possible to read a little post with any kind of documentation/explanation about this?
    This is a good question... I don't use this fully with the different statuses and returns.
    I always use
    Code:
    ProcessComplete.Finished = true;
    ProcessComplete.Success = true;
    return EventResult.Complete();
    when a "phase" in the automation is done;

    There're two phases in the automation Login phase and the "trying to play the video" phase

    First you start the login phase in the PerformLogin method, you're in this phase until you do the above ProcessComplete.Finished and so on...
    Then the Second phase starts in the PlayVideo method.

    The BrowserDocumentComplete is called on every "document ready" event (when the page redirected to or browsed to by setting a new value to the Url property is ready/completely loded).

    The most tricky part is to automate stuff when the site uses a lot of ajax and everything is async. When is the login process finished? How can I know where I'm in the automation process?

    I have made some important methods and properties bold.

    Other methods:
    Pause() - What to do OnPause...
    Play() - What to do OnPlay (play button pressed while the video already is playing)
    OnAction - other keyboard or remote events.

    What you are trying to achieve is some kind of deterministic automation... To do this I try to do some kind of simple state machine and to do this I often define an "state enum" to keep track on where I am and what "transition" to do next.


    Back to
    Code:
    ProcessComplete.Finished = true;
    ProcessComplete.Success = true;
    return EventResult.Complete();

    If ProcessComplete.Success = false; this could signal that something went wrong (e.g. the login) and the browser could exit with an error. @Jason Pyke could maybe describe how this should/could be used...

    I did NOT proof read this

    Edit: I wrote this related post yesterday: Swedish sites: SVT, TV4 Premium, UR, TV3, TV6, TV8, TV10, Kanal 5, 9 and 11 + Movie & Series sites


    EDIT AGAIN:
    And set a longer timeout in OnlineVideos.WebAutomation.BrowserHost.exe.config or App.config when debugging.
     
    Last edited:

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    I also have a question regarding BrowserPlayer based sites:

    I'm searching for a way to detect the end of playback (example for Amazon Prime) to be able to automatically close the player at end. (Otherwise the web page remains on screen until you hit "stop" on remote to close the window).

    I think this has do be implemented in JavaScript for the actual site, i.e. by listening to an event or by some polling of the loaded web page has changed.

    Are there any examples for this idea?
     

    Ministerk

    Super User
  • Team MediaPortal
  • Super User
  • November 28, 2007
    970
    826
    Uppsala
    Home Country
    Sweden Sweden
    I also have a question regarding BrowserPlayer based sites:

    I'm searching for a way to detect the end of playback (example for Amazon Prime) to be able to automatically close the player at end. (Otherwise the web page remains on screen until you hit "stop" on remote to close the window).

    I think this has do be implemented in JavaScript for the actual site, i.e. by listening to an event or by some polling of the loaded web page has changed.

    Are there any examples for this idea?
    I don't think there are any examples of this and how to do this depends on the site.
    Implementing this by injecting javascript listening for a specific event might work, one "simple" way of do this is:
    1) Inject a javascript event listener.
    2) On the event the javascript redirects the browser to another url, about:blank or something
    3) The BrowserDocumentComplete is going to be called when about:blank has loaded
    4) Quit the browser from BrowserDocumentComplete


    Edit:
    In some cases the url in the address bar is changed by the site when playback ends. If the page loads then you could use this and start from 3). If it does not load you might poll this from the connector with a timer interval fi you don't want to inject js.
     
    Last edited:

    Users who are viewing this thread

    Top Bottom