我有一个运行随机视频的 HTML 视频播放器。我有以下功能,可以根据视频观看百分比测试视频是否标记为已完成。VideoCompletionPercentage 是一个全局变量,通过从数据库中读取它来设置。我必须测试以下两个条件:
- 如果在数据库中设置了 VideoCompletionPercentage 之前看到视频,则验证视频是否标记为完成。
- 验证视频是否被标记为完成,如果它被向前跳过并看到直到 100%
我基于跳过布尔变量在两个 while 循环之间切换。有没有办法通过操纵while条件或任何其他方式将这两个do while循环组合成一个?提前感谢您的投入。
private void VideoPecentageCompletion(bool skip)
{
double videoSeenPercentage;
if (skip)
{
do
{
double.TryParse(Driver.FindElement(By.CssSelector("div[class=played]")).GetAttribute("aria-valuemax"), out double totalVideo);
double.TryParse(Driver.FindElement(By.CssSelector("div[class=played]")).GetAttribute("aria-valuenow"), out double videoProgress);
videoSeenPercentage = Math.Floor(videoProgress / totalVideo * 100);
} while (videoSeenPercentage < VideoCompletionPercentage);
}
else
{
do
{
double.TryParse(Driver.FindElement(By.CssSelector("div[class=played]")).GetAttribute("aria-valuemax"), out double totalVideo);
double.TryParse(Driver.FindElement(By.CssSelector("div[class=played]")).GetAttribute("aria-valuenow"), out double videoProgress);
videoSeenPercentage = Math.Floor(videoProgress / totalVideo * 100);
} while (videoSeenPercentage < 100);
}
}