views:

138

answers:

1

In our windows media center plugin we use the PlayMedia api to play Videos. This is the documented API by MS for playing videos and is documented in the SDK.

Eg.

AddInHost.Current.MediaCenterEnvironment.PlayMedia(Microsoft.MediaCenter.MediaType.Video, path, false)

In Vista, consistently, after this call we have a media experience ready for us in: AddInHost.Current.MediaCenterEnvironment.MediaExperience

However in Window 7 stuff is a bit more erratic and is seems that MediaExperience goes to la-la land after a certain amount of time or certain random actions.

How do I consistently play a video and go full screen in Window 7?

Are there any workarounds to getting this API to work consistently 100% of the time.

It seems the remoting channel just dies or something.

A: 

In case another poor soul has this issue, here is a workaround for win 7, MS have been really slow when it comes to fixing this.

        var mce = AddInHost.Current.MediaCenterEnvironment.MediaExperience;

        // great window 7 has bugs, lets see if we can work around them 
        if (mce == null) {
            System.Threading.Thread.Sleep(200);
            mce = AddInHost.Current.MediaCenterEnvironment.MediaExperience;
            if (mce == null) {
                try {
                    var fi = AddInHost.Current.MediaCenterEnvironment.GetType()
                        .GetField("_checkedMediaExperience", BindingFlags.NonPublic | BindingFlags.Instance);
                    if (fi != null) {
                        fi.SetValue(AddInHost.Current.MediaCenterEnvironment, false);
                        mce = AddInHost.Current.MediaCenterEnvironment.MediaExperience;
                    }

                } catch (Exception e) { 
                    // give up ... I do not know what to do 
                    Logger.ReportException("AddInHost.Current.MediaCenterEnvironment.MediaExperience is null", e);
                }

            }
Sam Saffron