Hi
I have 5 videos . I want that 1 video shoyld get complete . Browser shoyld get close . Another video should start.
With current code it opens 5 videos in 5 browsers
for (int i = 0; i < 4; i++)
{
RunVideo("youtube.com/watch?v=5X0BJrdsW56A?loop=1");
}
public static void RunVideo(string videolink)
{
Process process = new Process();
var _process = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", videolink);
//Process.Start(_process);
process.StartInfo = _process;
process.Start();
}
Thanks
Deepak TewatiaPosted Dec 18, 2022, 4:23 AM
Hi Ramco,
I have 3 solutions to solve your problem, please try any of them.
Solution-1
In the above code, You can use the Sleep method from the System.Threading namespace to pause the loop for 60 seconds (the duration of each video). Then, we use the Kill method from the Process class to close the browser.
Solution-2
The WaitForExit() method blocks the calling thread until the associated process terminates. This will allow the browser to play the video and then close before starting the next video.
Note that this solution assumes that the browser will close automatically after the video has finished playing. If the browser does not close automatically, you may need to find a way to close it programmatically. One option is to use the CloseMainWindow() method of the Process class, which attempts to close the main window of the process. You can use this method after calling WaitForExit() to close the browser if it is still open.
Solution-3
Also, you can use a while loop and a timer to achieve the same effect.
It will play the video, wait for 5 seconds, and then close the browser before moving on to the next video. You can adjust the wait time as needed.