Improve mpv set video owner (perhaps)

This commit is contained in:
Nikolaj Olsson 2017-10-22 08:25:17 +02:00
parent 879207ed20
commit d30f155fc1
2 changed files with 27 additions and 13 deletions

View File

@ -135,7 +135,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (subtitle.Paragraphs.Count > 0)
{
var prev = subtitle.Paragraphs[subtitle.Paragraphs.Count - 1];
if (prev.Text == p.Text && prev.StartTime.TotalMilliseconds == p.StartTime.TotalMilliseconds)
if (prev.Text == p.Text && Math.Abs(prev.StartTime.TotalMilliseconds - p.StartTime.TotalMilliseconds) < 0.01)
add = false;
}
if (add)

View File

@ -232,7 +232,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
return;
DoMpvCommand("frame-step");
_pausePosition = null;
_pausePosition = null;
}
public void GetPreviousFrame()
@ -427,29 +427,43 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
if (!string.IsNullOrEmpty(videoFileName))
{
_mpvInitialize.Invoke(_mpvHandle);
SetVideoOwner(ownerControl);
string videoOutput = "direct3d";
if (!string.IsNullOrWhiteSpace(Configuration.Settings.General.MpvVideoOutput))
videoOutput = Configuration.Settings.General.MpvVideoOutput;
_mpvSetOptionString(_mpvHandle, GetUtf8Bytes("vo"), GetUtf8Bytes(videoOutput)); // use "direct3d" or "opengl"
_mpvSetOptionString(_mpvHandle, GetUtf8Bytes("keep-open"), GetUtf8Bytes("always")); // don't auto close video
_mpvSetOptionString(_mpvHandle, GetUtf8Bytes("no-sub"), GetUtf8Bytes("")); // don't load subtitles
if (ownerControl != null)
{
for (int i = 0; i < 3; i++)
{
Application.DoEvents();
int mpvFormatInt64 = 4;
var windowId = ownerControl.Handle.ToInt64();
_mpvSetOption(_mpvHandle, GetUtf8Bytes("wid"), mpvFormatInt64, ref windowId);
}
}
DoMpvCommand("loadfile", videoFileName);
_videoLoadedTimer = new Timer { Interval = 50 };
_videoLoadedTimer.Tick += VideoLoadedTimer_Tick;
_videoLoadedTimer.Start();
SetVideoOwner(ownerControl);
}
}
private void SetVideoOwner(Control ownerControl)
{
if (ownerControl != null)
{
int iterations = 25;
int returnCode = -1;
int mpvFormatInt64 = 4;
var windowId = ownerControl.Handle.ToInt64();
while (returnCode != 0 && iterations > 0)
{
Application.DoEvents();
returnCode = _mpvSetOption(_mpvHandle, GetUtf8Bytes("wid"), mpvFormatInt64, ref windowId);
if (returnCode != 0)
{
iterations--;
System.Threading.Thread.Sleep(100);
}
}
}
}