1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-06 05:34:05 +02:00

Cleanup FormPlayer code and set sync timer interval to 15 instead of 10

This commit is contained in:
chylex 2017-08-12 19:08:17 +02:00
parent 03af6cecaa
commit 40ca923745
2 changed files with 28 additions and 11 deletions

View File

@ -36,7 +36,7 @@ private void InitializeComponent() {
//
// timerSync
//
this.timerSync.Interval = 10;
this.timerSync.Interval = 15;
this.timerSync.Tick += new System.EventHandler(this.timerSync_Tick);
//
// trackBarVolume

View File

@ -68,7 +68,9 @@ 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));
@ -78,9 +80,9 @@ private void timerSync_Tick(object sender, EventArgs e){
tablePanel.Visible = isCursorInside || isDragging;
if (tablePanel.Visible){
labelTime.Text = $"{Player.controls.currentPositionString} / {Player.currentMedia.durationString}";
labelTime.Text = $"{controls.currentPositionString} / {media.durationString}";
int value = (int)Math.Round(progressSeek.Maximum*Player.controls.currentPosition/Player.currentMedia.duration);
int value = (int)Math.Round(progressSeek.Maximum*controls.currentPosition/media.duration);
if (value >= progressSeek.Maximum){
progressSeek.Value = progressSeek.Maximum;
@ -93,10 +95,10 @@ private void timerSync_Tick(object sender, EventArgs e){
}
}
if (Player.controls.currentPosition > Player.currentMedia.duration){ // pausing near the end of the video causes WMP to play beyond the end of the video wtf
Player.controls.stop();
Player.controls.currentPosition = 0;
Player.controls.play();
if (controls.currentPosition > media.duration){ // pausing near the end of the video causes WMP to play beyond the end of the video wtf
controls.stop();
controls.currentPosition = 0;
controls.play();
}
if (isCursorInside && !wasCursorInside){
@ -109,6 +111,9 @@ private void timerSync_Tick(object sender, EventArgs e){
NativeMethods.SetForegroundWindow(ownerHandle);
}
}
Marshal.ReleaseComObject(media);
Marshal.ReleaseComObject(controls);
}
else{
Environment.Exit(Program.CODE_OWNER_GONE);
@ -122,12 +127,21 @@ private void timerData_Tick(object sender, EventArgs e){
private void progressSeek_MouseDown(object sender, MouseEventArgs e){
if (e.Button == MouseButtons.Left){
Player.controls.currentPosition = Player.currentMedia.duration*progressSeek.PointToClient(Cursor.Position).X/progressSeek.Width;
IWMPMedia media = Player.currentMedia;
IWMPControls controls = Player.controls;
controls.currentPosition = media.duration*progressSeek.PointToClient(Cursor.Position).X/progressSeek.Width;
Marshal.ReleaseComObject(media);
Marshal.ReleaseComObject(controls);
}
}
private void trackBarVolume_ValueChanged(object sender, EventArgs e){
Player.settings.volume = trackBarVolume.Value;
IWMPSettings settings = Player.settings;
settings.volume = trackBarVolume.Value;
Marshal.ReleaseComObject(settings);
if (timerSync.Enabled){
timerData.Stop();
@ -146,14 +160,17 @@ private void trackBarVolume_MouseUp(object sender, MouseEventArgs e){
// Controls & messages
private void TogglePause(){
IWMPControls controls = Player.controls;
if (isPaused){
Player.controls.play();
controls.play();
}
else{
Player.controls.pause();
controls.pause();
}
isPaused = !isPaused;
Marshal.ReleaseComObject(controls);
}
internal class MessageFilter : IMessageFilter{