Hi
I have 10 videos & i want them to execute in a loop . First video should run & browser should get closed , then second,third & so on
I want it in Web based application .
Thanks
Hi
I have 10 videos & i want them to execute in a loop . First video should run & browser should get closed , then second,third & so on
I want it in Web based application .
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tuhin PaulRank #7 · 71.9K reputationPosted Feb 22, 2023, 11:36 PM EST
Hi Ramco,
Assuming that you want to create a web-based application to play the videos in a loop, you can use JavaScript to achieve this functionality. Here's an example of how you can do it:
Here's some sample code that demonstrates this approach:
Video Loop Example var videoUrls = [ "video1.mp4", "video2.mp4", "video3.mp4", "video4.mp4", "video5.mp4", "video6.mp4", "video7.mp4", "video8.mp4", "video9.mp4", "video10.mp4" ]; var currentVideo = 0; var videoPlayer = null; var loopInterval = null; var loopDuration = 10000; // 10 seconds function startLoop() { // Create video player videoPlayer = document.createElement("video"); document.body.appendChild(videoPlayer); // Start loop loopInterval = setInterval(playNextVideo, loopDuration); } function playNextVideo() { // Stop current video if (videoPlayer) { videoPlayer.pause(); document.body.removeChild(videoPlayer); } // Play next video videoPlayer = document.createElement("video"); videoPlayer.src = videoUrls[currentVideo]; document.body.appendChild(videoPlayer); videoPlayer.play(); // Wait for video to finish setTimeout(nextVideo, videoPlayer.duration * 1000); } function nextVideo() { currentVideo = (currentVideo + 1) % videoUrls.length; } Start LoopThis code creates a web page with a "Start Loop" button. When the button is clicked, the startLoop() function is called, which creates a video player and starts the loopInterval. The playNextVideo() function is called by the loopInterval, which plays the next video in the array and waits for it to finish before moving on to the next video. When all the videos have been played, the loop stops.
Ramco RamcoRank #462 · 5.4K reputationPosted Feb 23, 2023, 12:25 AM EST
Hi Tuhin
I don't want button to be clicked. When i run application it should automatically loop the videos
Thanks
Vishal YelveRank #178 · 13.6K reputationPosted Feb 23, 2023, 9:06 AM EST
Hi Ramco,
Try this code I have Tested this and its working on IE Edge properly
public class Program { static async Task Main(string[] args) { List youtubevideoslinks = new List() { "http://www.youtube.com/watch?v=-wtIMTCHWuI", "http://youtube.com/watch?v=-wtIMTCHWuI", "http://m.youtube.com/watch?v=-wtIMTCHWuI", "https://www.youtube.com/watch?v=lalOy8Mbfdc", "https://youtube.com/watch?v=lalOy8Mbfdc", "https://m.youtube.com/watch?v=lalOy8Mbfdc"}; foreach (var item in youtubevideoslinks) { RunVideo(item); } } }public static void RunVideo(string videolink) { var process = new Process(); var _process = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", videolink); process.StartInfo = _process; process.Start(); Thread.Sleep(2000); process.CloseMainWindow(); process.Close(); }Ramco RamcoRank #462 · 5.4K reputationPosted Feb 23, 2023, 10:43 AM EST
Hi Vishal
On this line - process.CloseMainWindow();
i am getting below error - {"Process has exited, so the requested information is not available."}
Below is the code
protected void Page_Load(object sender, EventArgs e) { List urls = GetVideoUrls(); foreach (var item in urls) { RunVideo(item); } } private List GetVideoUrls() { List urls = new List(); string strConnString = ConfigurationManager.ConnectionStrings["Cnn"].ConnectionString; using (SqlConnection con = new SqlConnection(strConnString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "SELECT VideoId FROM videos"; cmd.Connection = con; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string videoId = reader.GetString(0); string url = $"https://www.youtube.com/watch?v={videoId}"; urls.Add(url); } reader.Close(); con.Close(); } } return urls; } public static void RunVideo(string videolink) { var process = new Process(); var _process = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", videolink); process.StartInfo = _process; process.Start(); Thread.Sleep(2000); process.CloseMainWindow(); process.Close(); }Thanks
Vishal YelveRank #178 · 13.6K reputationPosted Feb 23, 2023, 1:06 PM EST
Hi Ramco,
I have shared the code as console app. And as per your request you want to auto run the job. So I'll suggest go with the console app.
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 23, 2023, 12:51 AM EST
Hello Ramco,
You can use below code to run videos on load.
Your browser does not support the video tag. var videoUrls = [ "https://www.youtube.com/watch?v=TE66McLMMEw", "https://www.youtube.com/watch?v=hg4neStS1yA&t=1s" // Add more video URLs here ]; var currentIndex = 0; var videoElement = document.getElementById("myVideo"); function startLoop() { videoElement.addEventListener("ended", function() { currentIndex = (currentIndex + 1) % videoUrls.length; videoElement.src = videoUrls[currentIndex]; videoElement.play(); }); }Thanks
Naimish Makwana
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 23, 2023, 1:47 AM EST
Hello Ramco,
If you want to read video from Database. You need to modify your binddata method or you can create new method which will return List of Vides:
Example:
private List GetVideoUrls() { List urls = new List(); string strConnString = ConfigurationManager.ConnectionStrings["Cnn"].ConnectionString; using (SqlConnection con = new SqlConnection(strConnString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "SELECT Id FROM videos"; cmd.Connection = con; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int videoId = reader.GetInt32(0); string url = $"https://www.youtube.com/watch?v={videoId}"; urls.Add(url); } reader.Close(); con.Close(); } } return urls; }Then in page load method you need to return this urls as string to your UI
protected void Page_Load(object sender, EventArgs e) { List urls = GetVideoUrls(); string videoUrls = "var videoUrls = ["; for (int i = 0; i < urls.Count; i++) { videoUrls += "\"" + urls[i] + "\""; if (i < urls.Count - 1) { videoUrls += ", "; } } videoUrls += "];"; ClientScript.RegisterStartupScript(this.GetType(), "videoUrls", videoUrls, true); }Finaly at UI side you can access this variable.
// Use the videoUrls variable here console.log(videoUrls);Thanks
Naimish Makwana