Hi
I have below code . Only first Video runs then Youtube suggested Video Starts. I want that all videos in array should get displayed.
foreach (var video in videos)
{
_driver.Navigate().GoToUrl(video);
var timeElement = _driver.FindElement(By.XPath(XPATH_TIME));
string timeValue = timeElement.GetAttribute("innerText");
// Parse the timeValue to TimeSpan
if (TimeSpan.TryParse(timeValue, out TimeSpan videoDuration))
{
// Delay by the duration of the video
await Task.Delay(videoDuration);
}
else
{
// Handle parsing error, maybe log it or use a default delay
Console.WriteLine("Failed to parse video duration: " + timeValue);
await Task.Delay(TimeSpan.FromMinutes(1)); // Default delay
}
}
Thanks
Ramco RamcoPosted May 2, 2024, 10:09 AM
Hi Jayraj
Issue is now that ir runs only first video. After first Youtube suggested video starts not the second one in array.
Thanks
Jayraj ChhayaPosted May 2, 2024, 9:57 AM
Try these code
To resolve this issue, you can modify the code to await each video's playback individually without accumulating delays.
Ramco RamcoPosted May 2, 2024, 9:53 AM
Hi Jayraj
It opens all the videos but only the last video runs.
Thanks
Jayraj ChhayaPosted May 2, 2024, 9:38 AM
To ensure that all videos in the array are displayed sequentially without interruptions, you need to modify the code to handle each video's duration properly. The current implementation waits for the video duration using
Task.Delay, but it might not be accurate for all videos.One approach is to calculate the total duration of all videos and then play them one after the other. You can sum up the durations of all videos and create a cumulative delay to ensure seamless playback. Here's a high-level example of how you can achieve this: