Esempio n. 1
0
        public void KinectActionEventHandler(object sender, KinectRecognizedActionEventArgs e)
        {
            GestureAction action = e.ActionType;
            KinectActionRecognizedSource source = e.ActionSource;

            if (source == KinectActionRecognizedSource.Gesture)
            {
                if (action == GestureAction.INPUT_UP || action == GestureAction.INPUT_DOWN)
                {
                    // Ignore scroll actions while one is already in progress
                    if (scrollTimer.Enabled == false)
                    {
                        kodiStreamWriter.WriteLine(action.ToString());
                        scrollAction         = action; //Set the scroll action we want to do
                        scrollTimer.Interval = 1000;   //Set the interval
                        scrollTimer.Start();           //Start the timer
                    }
                }
                else if (action == GestureAction.INPUT_PREVIOUS || action == GestureAction.INPUT_NEXT)
                {
                    // Ignore scroll actions while one is already in progress
                    if (scrollTimer.Enabled == false)
                    {
                        kodiStreamWriter.WriteLine(action.ToString());
                        scrollAction         = action; //Set the scroll action we want to do
                        scrollTimer.Interval = 1000;   //TODO: Tune the scroll time.
                        scrollTimer.Start();           //Start the timer
                    }
                }
                else if (action == GestureAction.INPUT_SCROLLDONE)
                {
                    scrollTimer.Enabled = false; //Stop the scroll timer, set the action to null
                    scrollAction        = null;
                    scrollCount         = 0;
                }
                else if (action == GestureAction.VOLUME_DOWN || action == GestureAction.VOLUME_UP)
                {
                    //Set the volume action
                    volumeAction = action;

                    // Ignore volume actions while one is already in progress
                    if (scrollTimer.Enabled == false)
                    {
                        kodiStreamWriter.WriteLine(action.ToString() + " 5");
                        volumeTimer.Start(); //Start the timer
                    }
                }
                else if (action == GestureAction.VOLUME_DONE)
                {
                    volumeAction        = null;
                    volumeTimer.Enabled = false;
                }
                else if (action == GestureAction.PLAYER_REWIND || action == GestureAction.PLAYER_FORWARD)
                {
                    // Ignore seek actions while one is already in progress
                    if (seekInProgress == false)
                    {
                        kodiStreamWriter.WriteLine(action.ToString());
                        seekInProgress = true;
                    }
                }
                else if (action == GestureAction.PLAYER_SEEKDONE)
                {
                    if (seekInProgress)
                    {
                        if (videoPaused)
                        {
                            kodiStreamWriter.WriteLine(GestureAction.PLAYER_PAUSE.ToString());
                        }
                        else
                        {
                            kodiStreamWriter.WriteLine(GestureAction.PLAYER_PLAY.ToString());
                        }
                    }
                    seekInProgress = false;
                }
                else if (action == GestureAction.INPUT_SELECT)
                {
                    // Aliasing of select and play, there may be a better way to implement this.
                    kodiStreamWriter.WriteLine(action.ToString());
                    kodiStreamWriter.WriteLine(GestureAction.PLAYER_PLAY.ToString());
                    videoPaused = false;
                }
                else if (action == GestureAction.PLAYER_PAUSE)
                {
                    kodiStreamWriter.WriteLine(action.ToString());
                    videoPaused = true;
                }
                else if (action == GestureAction.INPUT_HOME)
                {
                    // Stop any playing content and return to the home screen.
                    kodiStreamWriter.WriteLine(GestureAction.PLAYER_STOP.ToString());
                    kodiStreamWriter.WriteLine(action.ToString());
                }
                else
                {
                    kodiStreamWriter.WriteLine(action.ToString());
                }
            }
            else
            {
                //the sender should be an AmbrSpeechRecognition object... capture a reference to it for later
                asr = (AmbrSpeechRecognition)sender;

                if (action == GestureAction.ACTIVATION_PHRASE)
                {
                    //Send a message to
                    //kodiStreamWriter.WriteLine("GUI_NOTIFICATION 'AMBr' 'Say A Command' 10000");
                    showNotification("Say a Command", "AMBr", 10000, true);
                    kodiStreamWriter.WriteLine("APPLICATION_MUTE");

                    speechTimer.Stop();
                    speechTimer.Interval = 10000;
                    speechTimer.Start();

                    allowSpeechEvents = true;
                }
                else if (allowSpeechEvents)
                {
                    //Source is a speech event

                    //kodiStreamWriter.WriteLine("GUI_NOTIFICATION 'AMBr' 'Say A Command' 2500");
                    showNotification(notificationTitle, notificationSubtitle, 2500);

                    speechTimer.Stop();
                    speechTimer.Interval = 2500;
                    speechTimer.Start();

                    if (action == GestureAction.VOLUME_UP)
                    {
                        kodiStreamWriter.WriteLine("VOLUME_UP 10");
                    }
                    else if (action == GestureAction.VOLUME_DOWN)
                    {
                        kodiStreamWriter.WriteLine("VOLUME_DOWN 10");
                    }
                    // Not fully implemented yet, currently just generates the grammar
                    else if (action == GestureAction.PLAY_MOVIE)
                    {
                        kodiStreamReader.DiscardBufferedData();
                        kodiStreamWriter.WriteLine("LS_MOVIES");
                        List <string> movies   = new List <string>();
                        string        currLine = kodiStreamReader.ReadLine();
                        while (!"DONE".Equals(currLine))
                        {
                            movies.Add(currLine);
                            currLine = kodiStreamReader.ReadLine();
                        }

                        asr.RecognizeItemList(kodiListToXmlDocument(movies));

                        // Do something to get the user's selection...
                        //kodiStreamWriter.WriteLine("GUI_NOTIFICATION 'Say a movie name' 'There are " + movies.Count.ToString() + " movies.' 10000");
                        playerIdType = "movieid";
                        showNotification("Say a movie title", "There are " + movies.Count.ToString() + " movies.", 10000, true);

                        speechTimer.Stop();
                        speechTimer.Interval = 10000;
                        speechTimer.Start();
                    }
                    else if (action == GestureAction.PLAY_MUSIC)
                    {
                        kodiStreamReader.DiscardBufferedData();
                        kodiStreamWriter.WriteLine("LS_MUSIC");
                        List <string> songs    = new List <string>();
                        string        currLine = kodiStreamReader.ReadLine();
                        while (!"DONE".Equals(currLine))
                        {
                            songs.Add(currLine);
                            currLine = kodiStreamReader.ReadLine();
                        }

                        asr.RecognizeItemList(kodiListToXmlDocument(songs));

                        // Do something to get the user's selection...
                        //kodiStreamWriter.WriteLine("GUI_NOTIFICATION 'Say a movie name' 'There are " + movies.Count.ToString() + " movies.' 10000");
                        playerIdType = "songid";
                        showNotification("Say a song name", "There are " + songs.Count.ToString() + " songs.", 10000, true);

                        speechTimer.Stop();
                        speechTimer.Interval = 10000;
                        speechTimer.Start();
                    }
                    else if (action == GestureAction.PLAYER_OPEN)
                    {
                        //Console.WriteLine(e.ActionData)
                        kodiStreamWriter.WriteLine("PLAYER_OPEN " + playerIdType + " " + e.ActionData);
                        asr.RecognizeItemList(null);
                    }
                    else if (action == GestureAction.PLAYER_OPEN_ERROR)
                    {
                        //TODO See if we really need this...
                        showNotification("Error", "Media Item Not Found", 10000);
                        asr.RecognizeItemList(null);
                    }
                    else
                    {
                        kodiStreamWriter.WriteLine(action.ToString());
                    }
                }
            }
        }
Esempio n. 2
0
 private static void KinectActionEventHandler(object sender, KinectRecognizedActionEventArgs e)
 {
     Console.WriteLine("Source: {0}   Action: {1} ", e.ActionSource.ToString(), e.ActionType.ToString());
 }