Ramco Ramco

Ramco Ramco

  • 442
  • 3.4k
  • 528.6k

Video opens in same Browser session

Feb 27 2023 12:26 PM

Hi

   I want when first video gets completed then in same session next video should be shown & so on. Currently if there r 4 videos , that open in different sessions

static Process browserProcess = null;
static async Task Main(string[] args)
{
    var datasource = @"MSSQLSERVER_2019";
    var database = "Videos"; 
    var username = "sa"; 
    var password = "sa@2019"; 

    string connectionString = @"Data Source=" + datasource + ";Initial Catalog="
        + database + ";Persist Security Info=True;User ID=" + username + ";Password=" + password;
    List<string> youtubevideoslinks = GetYouTubeVideoLinksFromDatabase(connectionString);
    foreach (var item in youtubevideoslinks)
    {
        RunVideo(item);
    }
}
public static List<string> GetYouTubeVideoLinksFromDatabase(string connectionString)
{
    List<string> youtubevideoslinks = new List<string>();

    string query = "SELECT videoid FROM videos"; 
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        SqlCommand command = new SqlCommand(query, connection);
        connection.Open();

        SqlDataReader reader = command.ExecuteReader();

        while (reader.Read())
        {
            string videoLink = reader["videoid"].ToString();
            youtubevideoslinks.Add(videoLink);
        }
        reader.Close();
    }

    return youtubevideoslinks;
}
public static void RunVideo(string videoId)
{
    string url = $"watch?v={videoId}";
    if (browserProcess == null || browserProcess.HasExited)
    {
        var process = new Process();
        var _process = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", url);
        process.StartInfo = _process;
        process.Start();
        browserProcess = process;
    }
    else
    {
        browserProcess.StartInfo.Arguments = url;
        browserProcess.Start();
    }

    Thread.Sleep(2000);
    browserProcess.CloseMainWindow();
    browserProcess.Close();
}

Thanks


Answers (2)