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

Capture Events!

Last post 02-22-2010, 2:49 AM by Xive. 4 replies.
Sort Posts: Previous Next
  •  01-21-2010, 1:07 AM 9531

    Capture Events!

    Hello,
    I'm working with Mcml & C# using windows 7 and Visual Studio and the SDK6..
    And i want to execute some code in C# whenever the user plays a video or go to full-screen in media center..

    Is this possible ?.. to listen to events from media center itself not from your app

    I have tried to capture it by doing this in the launch method in the background addin:


    if (host.MediaCenterEnvironment.MediaExperience.Transport.PlayState == Microsoft.MediaCenter.PlayState.Playing)
    {
         //Execute some code here.
    }


    It Compiles fine but the program stops responding inside media center..

    Also from the nature of background addins, it dies after doing its task.. i want to keep the addin running to listen to the play event at all times.

    I have seen similar problems but with dead ends..
    Is this actually possible ?

    Its really easy if you want to listen to the event from a video you made on your own app from a video element,
    But i find it really hard to listen to it from media center itself..

    I appreciate your help, thanks.
    Xive.
  •  01-26-2010, 1:56 AM 9536 in reply to 9531

    Re: Capture Events!

    For a background addin you need to keep the Launch method running in some way. Unlike MCML addins, as soon as the Launch method completes, the addin will terminate.

    Given what you're trying to do, the simplest way may be the PlayState check you are doing, inside a loop in the Launch method, with some kind of breakout code if the Uninitialize method of the addin is called.

    If this is similar to what you're currently doing, post the complete code so we can see what is going wrong.

    Another option may be to write an MSAS sink - this will receive MSAS events from Media Center (MSAS = media state aggregation service) of which play/stop are included.

    Cheers,
    Andrew
  •  02-18-2010, 1:48 AM 9555 in reply to 9536

    Re: Capture Events!

    Well i tried to make the loop inside the launch method.. but its not responding not sure why

    here is the complete code..
    built on the default background addin in visual studio..

    Launch.cs
    --------------------

        using System.Collections.Generic;
        using Microsoft.MediaCenter.Hosting;

        namespace EventDetect
        {
            public class MyAddIn : IAddInModule, IAddInEntryPoint
            {

                public void Initialize(Dictionary<string, object> appInfo, Dictionary<string, object> entryPointInfo)
                {
                }

                public void Uninitialize()
                {
                }

                public void Launch(AddInHost host)
                {
                    if (host != null && host.ApplicationContext != null)
                    {
                        host.ApplicationContext.SingleInstance = true;
                    }
                    Application app = new Application(host);

                    bool check = true;
                    while (check)
                    {
                        if (host.MediaCenterEnvironment.MediaExperience.Transport.PlayState == Microsoft.MediaCenter.PlayState.Playing)
                       {
                            app.Start("Xive");
                            check = false;
                       }
                    }
                }
            }
        }


    Application.cs
    --------------------
    using System.Collections.Generic;
    using System.Diagnostics;
    using Microsoft.MediaCenter;
    using Microsoft.MediaCenter.Hosting;
    using Microsoft.MediaCenter.UI;

    namespace EventDetect
    {
        public class Application : ModelItem
        {
            private AddInHost host;

            public Application(AddInHost host)
            {
                this.host = host;
            }

            public MediaCenterEnvironment MediaCenterEnvironment
            {
                get
                {
                    if (host == null) return null;
                    return host.MediaCenterEnvironment;
                }
            }

            public void Start( string state )
            {
                string temp = "The " + state + " application did something.";
                DialogTest(temp);
            }

            public void DialogTest(string strClickedText)
            {
                int timeout = 5;
                bool modal = true;
                string caption = Resources.DialogCaption;

                if (host != null)
                {
                    MediaCenterEnvironment.Dialog(strClickedText,
                                                  caption,
                                                  new object[] { DialogButtons.Ok },
                                                  timeout,
                                                  modal,
                                                  null,
                                                  delegate(DialogResult dialogResult) { });
                }
                else
                {
                    Debug.WriteLine("DialogTest");
                }
            }
        }
    }

    --------------------------
    error image

    Whenever i remove the check playing state condition the program runs fine.. :S

    Edit: On a different note, how to go about creating that MSAS Sink.. could you point me to a guide or a documentation, Thanks again.

    Xive.
  •  02-20-2010, 10:14 AM 9558 in reply to 9555

    Re: Capture Events!

    Concerning your MSAS Sink question. MSAS has been deprecated starting with the v6.0 SDK (hence there are no MSAS examples). Unfortunately MS really didn't provide a viable replacement for the functionality. In other words, MSAS is the best approach but it may not function in the future.

    That said, don't worry. Media Center's API has a long history of random functionality breaks. Using something that is merely deprecated is the least of your worries.  

    If you download the v5.x SDK, there is a sample implementation. In addition to this Damian Mehers has a blog about implementing a sink. Beyond this, you probably want to look at this thread over at TGB concerning 7MC support. Absalom has also started a running thread of MSAS bugs, but I have not had a chance to seriously take a look at it.

  •  02-22-2010, 2:49 AM 9562 in reply to 9558

    Re: Capture Events!

    Thanks David,
    I managed to get the Sink to work and write out the trace information..
    But i have another set back you could say..

    How do you check for tags value while other tags are set to true...

    I mean i want to check for the "MSPROPTAG_Play" while "MSPROPTAG_StreamingContentVideo" is true.

    which i cant seem to be able to do in damian guide, i can only check for one tag inside his for-loop like if "MSPROPTAG_Play" is set to true but i don't know if its the Music play or the Movie play !

    Another thing is that the Stop event for "Movies" is not being detected correctly
    see the log..
    ehmsas.exe Information: 0 : Tag MSPROPTAG_Play=True
    ehmsas.exe Information: 0 : Session.MediaStatusChange called
    ehmsas.exe Information: 0 : Tag MSPROPTAG_MediaTime=5109
    ehmsas.exe Information: 0 : Session.MediaStatusChange called
    ehmsas.exe Information: 0 : Tag MSPROPTAG_TrackTime=1
    ehmsas.exe Information: 0 : Session.MediaStatusChange called
    ehmsas.exe Information: 0 : Tag MSPROPTAG_TrackTime=2
    ehmsas.exe Information: 0 : Session.MediaStatusChange called
    ehmsas.exe Information: 0 : Tag MSPROPTAG_TrackTime=3
    ehmsas.exe Information: 0 : Session.MediaStatusChange called
    ehmsas.exe Information: 0 : Tag MSPROPTAG_TrackTime=4
    ehmsas.exe Information: 0 : Session.MediaStatusChange called
    ehmsas.exe Information: 0 : Tag MSPROPTAG_Pause=True
    ehmsas.exe Information: 0 : Session.MediaStatusChange called
    ehmsas.exe Information: 0 : Tag MSPROPTAG_Pause=True
    ehmsas.exe Information: 0 : Session.MediaStatusChange called
    ehmsas.exe Information: 0 : Tag MSPROPTAG_FS_Unknown=True
    ehmsas.exe Information: 0 : Session.Close called
    the blue line is the stop event,, its being detected as Unknown !
    --

    this issue is not as important as distinguishing between the music play event and the movie play event :S

    Thanks.

    Edit: I managed to do it, if anyone was having the same problem as me just make a bool property on the class level that state the current video streaming state, set it to false..
    and check for the "MSPROPTAG_StreamingContentVideo" if its there.. set your bool property value to true.
    and then when checking for "MSPROPTAG_Play" also checks (&&) if your property is true.

    Thanks guys for the help.

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