// 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 } }
private void TogglePause() { IWMPControls controls = Player.controls; if (isPaused) { controls.play(); } else { controls.pause(); } isPaused = !isPaused; Marshal.ReleaseComObject(controls); }
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); } }
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); } }