Exemple #1
0
        // Called every 5 seconds
        private void Timer_handle(object sender, EventArgs e)
        {
            IWMPControls controls = m_player.controls;

            WebcamCtrl.TakeSnapshot();
            m_imagePath = m_picturesDefaultPath;
            scan();

            // We need to check if the mood needs to be switched
            if (controls.currentItem != null &&
                controls.currentItem.duration - controls.currentPosition < 10.0)
            {
                DetectedResult emotion = getBestValue(m_averageEmotion);
                Mood           mood    = emotion.toMood();

                if (mood != m_currentMood)
                {
                    m_currentMood = mood;
                    ResetPlaylist(mood);
                }
            }

            if (controls.currentItem != null &&
                controls.currentItem.duration - controls.currentPosition < 2.0)
            {
                Track  track = m_songQueue.Dequeue();
                String uri   = m_videoPath + track.id + ".mp3";
                Log("Playing song: " + uri);
                m_player.URL = uri;
                controls.play();
                m_songQueue.Enqueue(track);
                // Box with artist and title track.artist and track.sonh
            }
        }
Exemple #2
0
        private void progressSeek_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                IWMPMedia    media    = Player.currentMedia;
                IWMPControls controls = Player.controls;

                controls.currentPosition = media.duration * progressSeek.GetProgress(progressSeek.PointToClient(Cursor.Position).X);

                Marshal.ReleaseComObject(media);
                Marshal.ReleaseComObject(controls);
            }
        }
Exemple #3
0
        private void TogglePause()
        {
            IWMPControls controls = Player.controls;

            if (isPaused)
            {
                controls.play();
            }
            else
            {
                controls.pause();
            }

            isPaused = !isPaused;
            Marshal.ReleaseComObject(controls);
        }
Exemple #4
0
        private void startCapturing()
        {
            try
            {
                // Display webcam video
                WebcamCtrl.StartPreview();
            }
            catch (Microsoft.Expression.Encoder.SystemErrorException ex)
            {
                MessageBox.Show("Device is in use by another application");
            }

            m_timer          = new System.Windows.Forms.Timer();
            m_timer.Tick    += new EventHandler(Timer_handle);
            m_timer.Interval = kInterval;
            m_timer.Start();

            m_timer2       = new System.Windows.Forms.Timer();
            m_timer2.Tick += (s, e) =>
            {
                if (m_player == null)
                {
                    return;
                }
                IWMPControls controls = m_player.controls;
                if (controls == null || controls.currentItem == null)
                {
                    return;
                }

                double pos      = controls.currentPosition;
                double duration = controls.currentItem.duration;
                if (duration > 0.1)
                {
                    TheSlider.Value = pos / duration;
                }
            };
            m_timer2.Interval = 400;
            m_timer2.Start();
        }
Exemple #5
0
        private void timerSync_Tick(object sender, EventArgs e)
        {
            if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect))
            {
                int width  = rect.Right - rect.Left + 1;
                int height = rect.Bottom - rect.Top + 1;

                IWMPMedia    media    = Player.currentMedia;
                IWMPControls controls = Player.controls;

                bool isCursorInside = ClientRectangle.Contains(PointToClient(Cursor.Position));

                ClientSize = new Size(Math.Max(MinimumSize.Width, Math.Min(media.imageSourceWidth, width * 3 / 4)), Math.Max(MinimumSize.Height, Math.Min(media.imageSourceHeight, height * 3 / 4)));
                Location   = new Point(rect.Left + (width - ClientSize.Width) / 2, rect.Top + (height - ClientSize.Height + SystemInformation.CaptionHeight) / 2);

                tablePanel.Visible = isCursorInside || isDragging;

                if (tablePanel.Visible)
                {
                    labelTime.Text = $"{controls.currentPositionString} / {media.durationString}";

                    int value = (int)Math.Round(progressSeek.Maximum * controls.currentPosition / media.duration);

                    if (value >= progressSeek.Maximum)
                    {
                        progressSeek.Value = progressSeek.Maximum;
                        progressSeek.Value = progressSeek.Maximum - 1;
                        progressSeek.Value = progressSeek.Maximum;
                    }
                    else
                    {
                        progressSeek.Value = value + 1;
                        progressSeek.Value = value;
                    }
                }

                if (controls.currentPosition > media.duration)  // pausing near the end of the video causes WMP to play beyond the end of the video wtf
                {
                    try{
                        controls.stop();
                        controls.currentPosition = 0;
                        controls.play();
                    }catch (AccessViolationException) {
                        // something is super retarded here because shit gets disposed between the start of this method and
                        // the controls.play() call even though it runs on the UI thread
                    }
                }

                if (isCursorInside && !wasCursorInside)
                {
                    wasCursorInside = true;
                }
                else if (!isCursorInside && wasCursorInside)
                {
                    wasCursorInside = false;

                    if (!Player.fullScreen && Handle == NativeMethods.GetForegroundWindow())
                    {
                        NativeMethods.SetForegroundWindow(ownerHandle);
                    }
                }

                Marshal.ReleaseComObject(media);
                Marshal.ReleaseComObject(controls);
            }
            else
            {
                Environment.Exit(Program.CODE_OWNER_GONE);
            }
        }
Exemple #6
0
        private void timerSync_Tick(object sender, EventArgs e)
        {
            if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect))
            {
                IWMPMedia    media    = Player.currentMedia;
                IWMPControls controls = Player.controls;

                int ownerLeft   = rect.Left;
                int ownerTop    = rect.Top;
                int ownerWidth  = rect.Right - rect.Left + 1;
                int ownerHeight = rect.Bottom - rect.Top + 1;

                // roughly matches MinimumSize for client bounds, adjusted a bit for weirdness with higher DPI
                int minWidth  = DpiScaled(356);
                int minHeight = DpiScaled(386);

                if (NativeMethods.GetClientRect(ownerHandle, out NativeMethods.RECT clientSize))
                {
                    minWidth  = Math.Min(minWidth, clientSize.Right);
                    minHeight = Math.Min(minHeight, clientSize.Bottom);
                }

                int maxWidth  = Math.Min(DpiScaled(media.imageSourceWidth), ownerWidth * 3 / 4);
                int maxHeight = Math.Min(DpiScaled(media.imageSourceHeight), ownerHeight * 3 / 4);

                bool isCursorInside = ClientRectangle.Contains(PointToClient(Cursor.Position));

                Size  newSize     = new Size(Math.Max(minWidth + 2, maxWidth), Math.Max(minHeight + 2, maxHeight));
                Point newLocation = new Point(ownerLeft + (ownerWidth - newSize.Width) / 2, ownerTop + (ownerHeight - newSize.Height + SystemInformation.CaptionHeight) / 2);

                if (ClientSize != newSize || Location != newLocation)
                {
                    ClientSize = newSize;
                    Location   = newLocation;
                    RefreshControlPanel();
                }

                if (isCursorInside || isDragging)
                {
                    labelTime.Text = $"{controls.currentPositionString} / {media.durationString}";

                    int value = (int)Math.Round(progressSeek.Maximum * controls.currentPosition / media.duration);

                    if (value >= progressSeek.Maximum)
                    {
                        progressSeek.Value = progressSeek.Maximum;
                        progressSeek.Value = progressSeek.Maximum - 1;
                        progressSeek.Value = progressSeek.Maximum;
                    }
                    else
                    {
                        progressSeek.Value = value + 1;
                        progressSeek.Value = value;
                    }

                    if (tablePanelFull.Enabled)
                    {
                        tablePanelFull.Visible = true;
                    }
                    else
                    {
                        tablePanelCompactBottom.Visible = true;
                        tablePanelCompactTop.Visible    = true;
                    }
                }
                else
                {
                    tablePanelFull.Visible          = false;
                    tablePanelCompactBottom.Visible = false;
                    tablePanelCompactTop.Visible    = false;
                }

                if (controls.currentPosition > media.duration)  // pausing near the end of the video causes WMP to play beyond the end of the video wtf
                {
                    try{
                        controls.stop();
                        controls.currentPosition = 0;
                        controls.play();
                    }catch (AccessViolationException) {
                        // something is super retarded here because shit gets disposed between the start of this method and
                        // the controls.play() call even though it runs on the UI thread
                    }
                }

                if (isCursorInside && !wasCursorInside)
                {
                    wasCursorInside = true;

                    if (IsCursorOverVideo)
                    {
                        Cursor.Current = Cursors.Default;
                    }
                }
                else if (!isCursorInside && wasCursorInside)
                {
                    wasCursorInside = false;

                    if (!Player.fullScreen && Handle == NativeMethods.GetForegroundWindow())
                    {
                        NativeMethods.SetForegroundWindow(ownerHandle);
                    }
                }

                Marshal.ReleaseComObject(media);
                Marshal.ReleaseComObject(controls);
            }
            else
            {
                Environment.Exit(Program.CODE_OWNER_GONE);
            }
        }