diff --git a/video/FormPlayer.Designer.cs b/video/FormPlayer.Designer.cs index cff5a0a2..aab7b586 100644 --- a/video/FormPlayer.Designer.cs +++ b/video/FormPlayer.Designer.cs @@ -88,6 +88,7 @@ private void InitializeComponent() { this.tablePanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tablePanel.Size = new System.Drawing.Size(400, 34); this.tablePanel.TabIndex = 1; + this.tablePanel.Visible = false; // // progressSeek // @@ -106,7 +107,7 @@ private void InitializeComponent() { // labelTime // this.labelTime.Dock = System.Windows.Forms.DockStyle.Fill; - this.labelTime.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular); + this.labelTime.Font = new System.Drawing.Font("Segoe UI", 9F); this.labelTime.Location = new System.Drawing.Point(138, 3); this.labelTime.Margin = new System.Windows.Forms.Padding(0, 3, 0, 5); this.labelTime.Name = "labelTime"; diff --git a/video/FormPlayer.cs b/video/FormPlayer.cs index 0fb2616a..58f4c9af 100644 --- a/video/FormPlayer.cs +++ b/video/FormPlayer.cs @@ -30,6 +30,12 @@ public FormPlayer(IntPtr handle, int volume, string url, string token){ this.videoUrl = url; this.pipe = DuplexPipe.CreateClient(token); this.pipe.DataIn += pipe_DataIn; + + if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect)){ + ClientSize = new Size(0, 0); + Location = new Point((rect.Left+rect.Right)/2, (rect.Top+rect.Bottom)/2); + Opacity = 0; + } player = new ControlWMP{ Dock = DockStyle.Fill @@ -100,6 +106,11 @@ private void player_PlayStateChange(int newState){ timerSync.Start(); NativeMethods.SetWindowOwner(Handle, ownerHandle); Cursor.Current = Cursors.Default; + + SuspendLayout(); + timerSync_Tick(timerSync, EventArgs.Empty); + Opacity = 1; + ResumeLayout(true); } } @@ -131,9 +142,14 @@ private void timerSync_Tick(object sender, EventArgs e){ int maxHeight = Math.Min(media.imageSourceHeight, ownerHeight*3/4); bool isCursorInside = ClientRectangle.Contains(PointToClient(Cursor.Position)); - - ClientSize = new Size(Math.Max(minWidth, maxWidth), Math.Max(minHeight, maxHeight)); - Location = new Point(ownerLeft+(ownerWidth-ClientSize.Width)/2, ownerTop+(ownerHeight-ClientSize.Height+SystemInformation.CaptionHeight)/2); + + Size newSize = new Size(Math.Max(minWidth, maxWidth), Math.Max(minHeight, 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; + } tablePanel.Visible = isCursorInside || isDragging; @@ -152,7 +168,7 @@ private void timerSync_Tick(object sender, EventArgs e){ 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();