mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-17 20:34:09 +02:00
Fix video player going past the end of a video when paused near the end
This commit is contained in:
parent
91bb2f4df0
commit
5ecf3c4147
@ -13,6 +13,8 @@ partial class FormPlayer : Form{
|
|||||||
private bool isPaused;
|
private bool isPaused;
|
||||||
private bool isDragging;
|
private bool isDragging;
|
||||||
|
|
||||||
|
private WindowsMediaPlayer Player => player.Ocx;
|
||||||
|
|
||||||
public FormPlayer(IntPtr handle, int volume, string url){
|
public FormPlayer(IntPtr handle, int volume, string url){
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
@ -27,12 +29,12 @@ public FormPlayer(IntPtr handle, int volume, string url){
|
|||||||
Controls.Add(player);
|
Controls.Add(player);
|
||||||
player.EndInit();
|
player.EndInit();
|
||||||
|
|
||||||
player.Ocx.enableContextMenu = false;
|
Player.enableContextMenu = false;
|
||||||
player.Ocx.uiMode = "none";
|
Player.uiMode = "none";
|
||||||
player.Ocx.settings.setMode("loop", true);
|
Player.settings.setMode("loop", true);
|
||||||
|
|
||||||
player.Ocx.MediaChange += player_MediaChange;
|
Player.MediaChange += player_MediaChange;
|
||||||
player.Ocx.MediaError += player_MediaError;
|
Player.MediaError += player_MediaError;
|
||||||
|
|
||||||
trackBarVolume.Value = volume; // changes player volume too if non-default
|
trackBarVolume.Value = volume; // changes player volume too if non-default
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ public FormPlayer(IntPtr handle, int volume, string url){
|
|||||||
// Events
|
// Events
|
||||||
|
|
||||||
private void FormPlayer_Load(object sender, EventArgs e){
|
private void FormPlayer_Load(object sender, EventArgs e){
|
||||||
player.Ocx.URL = videoUrl;
|
Player.URL = videoUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void player_MediaChange(object item){
|
private void player_MediaChange(object item){
|
||||||
@ -63,7 +65,7 @@ private void timerSync_Tick(object sender, EventArgs e){
|
|||||||
if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect)){
|
if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect)){
|
||||||
int width = rect.Right-rect.Left+1;
|
int width = rect.Right-rect.Left+1;
|
||||||
int height = rect.Bottom-rect.Top+1;
|
int height = rect.Bottom-rect.Top+1;
|
||||||
IWMPMedia media = player.Ocx.currentMedia;
|
IWMPMedia media = Player.currentMedia;
|
||||||
|
|
||||||
ClientSize = new Size(Math.Min(media.imageSourceWidth, width*3/4), Math.Min(media.imageSourceHeight, height*3/4));
|
ClientSize = new Size(Math.Min(media.imageSourceWidth, width*3/4), Math.Min(media.imageSourceHeight, height*3/4));
|
||||||
Location = new Point(rect.Left+(width-ClientSize.Width)/2, rect.Top+(height-ClientSize.Height+SystemInformation.CaptionHeight)/2);
|
Location = new Point(rect.Left+(width-ClientSize.Width)/2, rect.Top+(height-ClientSize.Height+SystemInformation.CaptionHeight)/2);
|
||||||
@ -71,9 +73,9 @@ private void timerSync_Tick(object sender, EventArgs e){
|
|||||||
tablePanel.Visible = ClientRectangle.Contains(PointToClient(Cursor.Position)) || isDragging;
|
tablePanel.Visible = ClientRectangle.Contains(PointToClient(Cursor.Position)) || isDragging;
|
||||||
|
|
||||||
if (tablePanel.Visible){
|
if (tablePanel.Visible){
|
||||||
labelTime.Text = $"{player.Ocx.controls.currentPositionString} / {player.Ocx.currentMedia.durationString}";
|
labelTime.Text = $"{Player.controls.currentPositionString} / {Player.currentMedia.durationString}";
|
||||||
|
|
||||||
int value = (int)Math.Round(progressSeek.Maximum*player.Ocx.controls.currentPosition/player.Ocx.currentMedia.duration);
|
int value = (int)Math.Round(progressSeek.Maximum*Player.controls.currentPosition/Player.currentMedia.duration);
|
||||||
|
|
||||||
if (value >= progressSeek.Maximum){
|
if (value >= progressSeek.Maximum){
|
||||||
progressSeek.Value = progressSeek.Maximum;
|
progressSeek.Value = progressSeek.Maximum;
|
||||||
@ -85,6 +87,12 @@ private void timerSync_Tick(object sender, EventArgs e){
|
|||||||
progressSeek.Value = value;
|
progressSeek.Value = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Environment.Exit(Program.CODE_OWNER_GONE);
|
Environment.Exit(Program.CODE_OWNER_GONE);
|
||||||
@ -97,11 +105,11 @@ private void timerData_Tick(object sender, EventArgs e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void progressSeek_Click(object sender, EventArgs e){
|
private void progressSeek_Click(object sender, EventArgs e){
|
||||||
player.Ocx.controls.currentPosition = player.Ocx.currentMedia.duration*progressSeek.PointToClient(Cursor.Position).X/progressSeek.Width;
|
Player.controls.currentPosition = Player.currentMedia.duration*progressSeek.PointToClient(Cursor.Position).X/progressSeek.Width;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void trackBarVolume_ValueChanged(object sender, EventArgs e){
|
private void trackBarVolume_ValueChanged(object sender, EventArgs e){
|
||||||
player.Ocx.settings.volume = trackBarVolume.Value;
|
Player.settings.volume = trackBarVolume.Value;
|
||||||
|
|
||||||
if (timerSync.Enabled){
|
if (timerSync.Enabled){
|
||||||
timerData.Stop();
|
timerData.Stop();
|
||||||
@ -121,10 +129,10 @@ private void trackBarVolume_MouseUp(object sender, MouseEventArgs e){
|
|||||||
|
|
||||||
private void TogglePause(){
|
private void TogglePause(){
|
||||||
if (isPaused){
|
if (isPaused){
|
||||||
player.Ocx.controls.play();
|
Player.controls.play();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
player.Ocx.controls.pause();
|
Player.controls.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
isPaused = !isPaused;
|
isPaused = !isPaused;
|
||||||
|
Loading…
Reference in New Issue
Block a user