The Media Center Sandbox

Resources and discussion for developing experiences in the Windows Media Center platform.
Welcome to The Media Center Sandbox Sign in | Join | Help
in Search

MediaExperience RemotingException (Requested Service not found)

Last post 09-04-2008, 5:22 PM by davidtjudd. 9 replies.
Sort Posts: Previous Next
  •  08-02-2008, 9:42 AM 8000

    MediaExperience RemotingException (Requested Service not found)

    In my PlayMedia() method I have

    object mediatransport = AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport;
    ((MediaTransport)mediatransport).PropertyChanged += new PropertyChangedEventHandler(mt_PC);

    so I can find out when a file has been stopped/paused etc. I also had to include something polling the transport every so often so it would not die on me, which I did by including

    Microsoft.MediaCenter.UI.Application.DeferredInvokeOnWorkerThread(new DeferredHandler(KeepAlive), GetPosition, mediatransport);

    KeepAlive polls mediatransport once a minute as long as Position != null, which keeps the object alive for as long as required. This all works fine (some CPU overhead, but I'll optimize this all once it's working 100%).

    The problem I'm having is that once a file has completed playing and another file is not started within a minute (or so) I get the RemotingException thrown when trying to setup the mediatransport as in my first line of code above. Any ideas on what I'm doing wrong here?

    The actual MediaCenterEnvironment.PlayMedia() is called before I'm setting up the transport object (and video starts playing before the crash) so it should be there - and indeed it always is the first time the application is started and my PlayMedia() is invoked (as well as all subsequent calls within the given timeframe).

  •  08-02-2008, 1:18 PM 8001 in reply to 8000

    Re: MediaExperience RemotingException (Requested Service not found)

    I'd suspect that the issue here is that the transport is associated with the video being played; when the video goes away, the transport gets cleaned up too.  

    Instead of passing the MediaTransport into the worker thread, have you tried accessing it through the AddInHost.Current instead?  You might find that you get a different error if you do (e.g. null reference) which you can handle better.

    Cheers,
    Andrew

  •  08-02-2008, 3:55 PM 8002 in reply to 8001

    Re: MediaExperience RemotingException (Requested Service not found)

    That's along the lines of what I initially thought [being associated with playing video]. Thing is; the crash occurs in

    object mediatransport = AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport;

    (from memory; the MediaExperience is fine - all it's objects are throwing RemoteExceptions).

    Now, this line of code is never executed by itself, it is always preceded by a MediaCenterEnvironment.PlayMedia() call which does indeed start a new video (and I thought, setup a brand spanking new MediaExperience).

    I was leaning towards this being caused by the "old" mediatransport object being kept alive for 60 seconds after the current video finished playing (and indeed, if I start another video within these 60s everything is hunky dory) but I still figured that if the transport has been collected and cleaned up a new one would be created no problem as there is now a new file playing. What I can't really get my head around is the fact it works fine the first time the application is started - always, but press stop (or let the video complete), wait 1 minute and try another file, the file starts playing immediately followed by a crash.

    ---edit---
    So, after more fiddling it turns out neither of "my" methods are responsible for this (at least it doesn't seem like they are). I've commented out the EventHandler and DeferredInvokeOnWorkerThread but it still throws a wobbly after leaving it alone for a minute plus before starting the next file. Removing the line setting up the object all is good again, but then I'm back to square one with no reliable way of catching when a file is stopped?

  •  08-03-2008, 6:40 AM 8003 in reply to 8002

    Re: MediaExperience RemotingException (Requested Service not found)

    ---edit2---
    Hmm, so I keep trying to get this functioning and I'm just digging myself deeper and deeper I think.

    I have a feeling the MediaExperience object is flawed itself? I've seen various comments towards this previously, but when playing around with various scenarios now I've had the Pause button automagically restart videos from the beginning, PlayState.Stopped not happening (the file was stopped though) and god knows what else. Reverted back to the code I knew was working (in terms of catching PlayState.Stop and Positioning) did nothing, restarting Media Center and everything is back to normal again (albeit with the original issue present).

    Ok, different tactic - can someone shed some light on what's the recommended way of finding out when a mediafile is stopped/paused (using a MCML timer is no good - I need notification as soon as it happens to backup the pagestack and write various information to a DB). Dammit, all I want is an event fireing when a file is stopped along with the complete MediaTransport information.

     

    ---edit3---
    So a thought occured to me - could the new issues I ran into (pause/stop etc not working properly) have anything to do with what's being discussed here? I remember a lot of shouting over bugs in KB950126 when first released (which were somewhat similar to my troubles now) although I never managed to see them myself on any of my boxes.

  •  09-03-2008, 11:14 AM 8316 in reply to 8003

    Re: MediaExperience RemotingException (Requested Service not found)

    MSAS will provide state information.  I use it in my addin to react to playback events (I don't control the experience).
  •  09-04-2008, 5:51 AM 8319 in reply to 8316

    Re: MediaExperience RemotingException (Requested Service not found)

    Thanks, I'm aware of that (although I have seen posts with regard to this being broke in TV-Pack also?), but it seems like a very convoluted way of getting at this kind of data - which I was perfectly capable of querying before the "update". I still think this is something MS needs to address (MediaExperience being null or faulted) and as soon as they do that I believe my old code will spring back into life again by itself.
  •  09-04-2008, 6:51 AM 8320 in reply to 8319

    Re: MediaExperience RemotingException (Requested Service not found)

    To get this working under 5.1 I wrapped my playmedia in a singleton. when the first call to playmedia is made, I start polling every 50sec. This continues for the life of the app. This issue you are seeing with media being stopped for more than ~1min is corrected by this hack.

    Works great for everything but fso based DVD mediatype. Those are randomly crashing VMC completely and I have not bothered to trace yet.

    I can provide my wrapper to this thread when I get home tonight if you need more to go on.

     

    EDIT: Having to do this bothers me.

  •  09-04-2008, 12:24 PM 8323 in reply to 8319

    Re: MediaExperience RemotingException (Requested Service not found)

    emigrating:
    Thanks, I'm aware of that (although I have seen posts with regard to this being broke in TV-Pack also?), but it seems like a very convoluted way of getting at this kind of data - which I was perfectly capable of querying before the "update". I still think this is something MS needs to address (MediaExperience being null or faulted) and as soon as they do that I believe my old code will spring back into life again by itself.


    I completely agree, but I don't think it's likely that we will see a fix anytime soon.  I haven't noticed MSAS being more broken than pre-pack; although there hasn't been a great way (or need) for me to test it thoroughly.
  •  09-04-2008, 3:23 PM 8325 in reply to 8323

    Re: MediaExperience RemotingException (Requested Service not found)

    davidtjudd: A quick code sample would be much appreciated indeed. I did infact do something similar back when, and keeping the one object alive via polling seemed to work, but I then ran into other issues where it would still fail after a much longer time - especially if the playing video stopped by itself instead of the user stopping it. But yeah, if you feel like posting your wrapper ... many thanks.

    babqvant: To be honest, I've given up on a fix being provided. When they don't even acknowledge the fact during betatesting it's a lost cause for me. Good info on MSAS not being more broken though. If that is the case it's definitely worth me looking into.

  •  09-04-2008, 5:22 PM 8329 in reply to 8325

    Re: MediaExperience RemotingException (Requested Service not found)

    emigrating- Here ya go, stripped my code out so it is barebones. This works for me as long as I don't deal with DVD video_ts content. As I mentioned before I'm still getting random crashes out of them.

    Concerning the eHome team actually addressing this, I'm not holding my breath.

    class PlayHandler

    {

    private static PlayHandler instance;

    private System.Timers.Timer aTimer;

    private AddInHost host;

    private PlayHandler()

    {

    this.Start();

    }

    public static PlayHandler Instance

    {

    get

    {

    if (instance == null)

    {

    instance = new PlayHandler();

    }

    return instance;

    }

    }

    public void PlayMediaEx(MediaType mediaType, object media, bool addToQueue)

    {

    try

    {

    Microsoft.MediaCenter.Hosting.AddInHost host = Microsoft.MediaCenter.Hosting.AddInHost.Current;

    MediaCenterEnvironment mce = host.MediaCenterEnvironment;

    mce.PlayMedia(mediaType, media, addToQueue);

    mce.MediaExperience.GoToFullScreen();

    if (this.aTimer == null)

    this.StartTimer();

    }

    catch{}

    }

    private void StartTimer()

    {

    aTimer = new System.Timers.Timer();

    aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

    // Set the Interval to 50 seconds.

    aTimer.Interval = 50000;

    aTimer.Enabled = true;

    }

    private void OnTimedEvent(object source, ElapsedEventArgs e)

    {

    try

    {

    //keep mce from completely crashing!

    PlayState p = this.CurrentMediaTransport.PlayState;

    }

    catch { }

    }

    public MediaTransport CurrentMediaTransport

    {

    get

    {

    this.host = AddInHost.Current;

    MediaCenterEnvironment env = host.MediaCenterEnvironment;

    if (env != null)

    {

    MediaExperience exp = env.MediaExperience;

    if (exp != null) return exp.Transport;

    }

    return null;

    }

    }

    private void Start()

    {

    MediaTransport mt = CurrentMediaTransport;

    if (mt != null)

    {

    mt.PropertyChanged += new PropertyChangedEventHandler(mt_PropertyChanged);

    }

    else

    {

    System.Timers.Timer t = new System.Timers.Timer();

    t.Elapsed += new ElapsedEventHandler(t_Elapsed);

    t.AutoReset = false;

    t.Interval = 1000;

    t.Enabled = true;

    }

    }

    private void t_Elapsed(object sender, ElapsedEventArgs e)

    {

    this.Start();

    }

    private void mt_PropertyChanged(IPropertyObject sender, string property)

    {

    if (property == "PlayState")

    {

    PlayState state = ((MediaTransport)sender).PlayState;

    TimeSpan position = ((MediaTransport)sender).Position;

    if (state == PlayState.Finished || state == PlayState.Stopped)

    {

    //do something useful with that frozen screen

    Microsoft.MediaCenter.UI.Application.DeferredInvoke(NavigateToPlayPage, sender);

    }

    }

    }

    }

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems