【问题标题】:MediaPlayer returning wrong mouse positionMediaPlayer 返回错误的鼠标位置
【发布时间】:2014-07-19 20:16:59
【问题描述】:

我在使用 MediaPlayer 组件时遇到了一个奇怪的问题 这似乎是 API 或 Delphi 的错误。 我直接在 Form2 画布上显示视频并允许 用户在窗口内缩放和拖动视频。 我使用 Form2.MouseDown 和 MouseUp 事件来拖动。

阻力表现不正常,我追踪了问题 事件中窗口坐标的使用不一致。 MPG 或 WMV 视频(压缩)将报告 MouseDown 相对于视频的坐标,但相对于 MouseUp 到表格。 AVI 视频(未压缩)将同时报告 相对于表格。

我在 Windows 7 中使用 Delphi XE3。 有没有其他人遇到过这个异常,我该怎么办 获得一致的 X,Y 坐标?

7/20 添加:

我不知道 MCVE 是什么意思,但我添加了一些代码以防有人 想尝试复制问题。 Label1 & Label2 报告鼠标坐标,如果视频被移动 超出(0,0)位置,然后坐标将随着鼠标跳动 跨入或跨出视频。它不应该这样做,它应该 总是报告相对于窗口的坐标,而不是视频。 FormMouseUp 将始终相对于窗口报告。 FormMouseDown 和 FormMouseMove 来回跳转。

procedure TForm1.MFLoadFileClick(Sender: TObject);
begin
  MediaPlayer1.Open;
  MediaPlayer1.Display := Form2;
end;

procedure TForm2.FormMouseDown(Sender: TObject; 
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Label1.Caption := IntToStr(X); {diag}
  Label2.Caption := IntToStr(Y); {diag}
  VidLoc := Form1.MediaPlayer1.DisplayRect;
  mX := X;   mY := Y;
  MouseDown := True;
end;

procedure TForm2.FormMouseMove(Sender: TObject; 
  Shift: TShiftState; X, Y: Integer);
begin
  Label1.Caption := IntToStr(X); {diag}
  Label2.Caption := IntToStr(Y); {diag}
end;

procedure TForm2.FormMouseUp(Sender: TObject; 
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var  VL : tRect;
begin
  Label1.Caption := IntToStr(X); {diag}
  Label2.Caption := IntToStr(Y); {diag}
  if (MouseDown and Form1.Loaded) then begin
    VL := VidLoc;
    VL.Left := VidLoc.Left - mX + X;
    VL.Top  := VidLoc.Top  - mY + Y;
    Form1.MediaPlayer1.DisplayRect := VL;
    Form1.MediaPlayer1.Step;
  end;
  MouseDown := False;
end;

【问题讨论】:

  • 请为此提供一个 MCVE
  • 我可以复制那个。您不需要两个表单和鼠标事件中的所有代码来复制,但没关系。无论如何,我只能说 VCL 似乎没有参与其中。 WM_LBUTTONDOWN 与相对于“ActiveMovie Window”的坐标一起发送,尽管该消息是发往表单的。我建议你使用面板或其他东西来移动。
  • 面板也会发生同样的事情。
  • @Humanoid1000 On MCVE。请尽最小的努力。
  • @Humanoid - 当您使用面板时,您不会修改媒体播放器的显示区域,对吧?

标签: delphi mouse


【解决方案1】:

奇怪的是,在面板中移动视频不起作用,但移动面板可以。 我不想这样做,因为它需要跟踪太多对象,但它必须这样做。
移动面板使用与上面相同的代码,但具有其他各种属性。

【讨论】:

  • 一点也不奇怪,玩家总是在其父级中的 (0, 0) 处。这就是为什么我建议“..一个面板或移动的东西”.
猜你喜欢
  • 1970-01-01
  • 2013-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多