Youtube Videos in ein Programm einbinden?

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    • Werbung zur Unterstützung des Forums ( Bitte AddBlocker deaktivieren )

    • Quellcode

      1. using System;
      2. public partial class _DEMO : System.Web.UI.Page
      3. {
      4. #region init settings
      5. // player width
      6. private int _W = 640;
      7. // player height
      8. private int _H = 505;
      9. // autoplay disabled
      10. bool auto = false;
      11. #endregion
      12. #region Page Load event
      13. protected void Page_Load(object sender, EventArgs e)
      14. {
      15. if (!IsPostBack)
      16. {
      17. #region Start mode customization via Web Query String
      18. int idx = 0;
      19. string qry = "";
      20. // Web Query to set autoplay option
      21. try {
      22. qry = "auto";
      23. qry = (Request.QueryString[qry] == null) ?
      24. "" : Request.QueryString[qry];
      25. if (qry != "") { auto = Boolean.Parse(qry); }
      26. } catch { }
      27. // Web Query to set item index
      28. try {
      29. qry = "item";
      30. qry = (Request.QueryString[qry] == null) ?
      31. "" : Request.QueryString[qry];
      32. if (qry != "") { idx = int.Parse(qry); }
      33. } catch { }
      34. #endregion
      35. // set selected index
      36. cmbPlaylist.SelectedIndex = idx;
      37. // generate script on page load
      38. Literal1.Text = YouTubeScript.Get
      39. (cmbPlaylist.SelectedValue, auto, _W, _H);
      40. }
      41. else
      42. {
      43. // generate script on page postback
      44. Literal1.Text = YouTubeScript.Get
      45. (cmbPlaylist.SelectedValue, false, _W, _H);
      46. }
      47. }
      48. #endregion
      49. #region User events
      50. /// <summary>
      51. /// Script to start video at predefined time, change border color
      52. /// </summary>
      53. protected void Button1_Click(object sender, EventArgs e)
      54. {
      55. // set start time = 15 sec, change border colors
      56. Literal1.Text =
      57. YouTubeScript.Get(cmbPlaylist.SelectedValue, true,
      58. _W, _H, true, "maroon", "", 15);
      59. }
      60. /// <summary>
      61. /// Script to start video at predefined time, remove border
      62. /// </summary>
      63. protected void Button2_Click(object sender, EventArgs e)
      64. {
      65. // set start time = 60 sec, remove border
      66. Literal1.Text =
      67. YouTubeScript.Get(cmbPlaylist.SelectedValue, true,
      68. _W, _H, false, "", "", 60);
      69. }
      70. #endregion
      71. }
      Alles anzeigen


      Quellcode

      1. using System;
      2. using System.Text;
      3. ///*****************************************************************************
      4. /// <summary>
      5. /// Generate Javascript to embed YouTube Video Player in ASP.NET web page
      6. /// </summary>
      7. public static class YouTubeScript
      8. {
      9. #region YouTube Player default script: no autoplay, 320x240
      10. /// <summary>
      11. /// YouTube Player default script: no autoplay, 320x240
      12. /// </summary>
      13. /// <param name="id">id</param>
      14. /// <param name="auto">int</param>
      15. /// <returns>string</returns>
      16. public static string Get(string id)
      17. { return Get(id, false, 320, 240); }
      18. #endregion
      19. #region YouTube Player script w/autoplay option (320x240)
      20. /// <summary>
      21. /// YouTube Player script w/autoplay option (320x240)
      22. /// </summary>
      23. /// <param name="id">id</param>
      24. /// <param name="auto">bool</param>
      25. /// <returns>string</returns>
      26. public static string Get(string id, bool auto)
      27. { return Get(id, auto, 320, 240); }
      28. #endregion
      29. #region YouTube Player script w/autoplay option (320x240)
      30. /// <summary>
      31. /// YouTube Player script w/autoplay option (320x240)
      32. /// </summary>
      33. /// <param name="id">id</param>
      34. /// <param name="auto">int</param>
      35. /// <returns>string</returns>
      36. public static string Get(string id, int auto)
      37. { return Get(id, ((auto == 1) ? true : false), 320, 240); }
      38. #endregion
      39. #region YouTube Player script w/selectable: autoplay and W/H
      40. /// <summary>
      41. /// YouTube Player script w/selectable: autoplay and W/H options
      42. /// </summary>
      43. /// <param name="id">id</param>
      44. /// <param name="auto">bool</param>
      45. /// <param name="W">int</param>
      46. /// <param name="H">int</param>
      47. /// <returns>string</returns>
      48. public static string Get(string id, bool auto, int W, int H)
      49. { return Get(id, auto, W, H, true); }
      50. #endregion
      51. #region YouTube Player script w/selectable: autoplay, W/H and default border
      52. /// <summary>
      53. /// YouTube Player script w/selectable: autoplay, W/H, default border color
      54. /// </summary>
      55. /// <param name="id">id</param>
      56. /// <param name="auto">bool</param>
      57. /// <param name="W">int</param>
      58. /// <param name="H">int</param>
      59. /// <param name="Border">bool</param>
      60. /// <returns>string</returns>
      61. public static string Get(string id, bool auto, int W, int H, bool Border)
      62. { return Get(id, auto, W, H, Border, "0x2b405b", "0x6b8ab6",0 ); }
      63. #endregion
      64. #region YouTube Player script w/selectable: autoplay, W/H and border color
      65. /// <summary>
      66. /// YouTube Player script w/selectable: autoplay, W/H and border color
      67. /// </summary>
      68. /// <param name="id">id</param>
      69. /// <param name="auto">bool</param>
      70. /// <param name="W">int</param>
      71. /// <param name="H">int</param>
      72. /// <param name="Border">bool</param>
      73. /// <param name="C1">string</param>
      74. /// <param name="C2">string</param>
      75. /// <returns>string</returns>
      76. public static string Get
      77. (string id,
      78. bool auto,
      79. int W,
      80. int H,
      81. string C1,
      82. string C2)
      83. { return Get(id, auto, W, H, true, C1,C2, 0); }
      84. #endregion
      85. #region YouTube Player script w/selectable: autoplay, W/H and border color
      86. /// <summary>
      87. /// YouTube Player script w/selectable: autoplay, W/H and border color
      88. /// </summary>
      89. /// <param name="id">id</param>
      90. /// <param name="auto">bool</param>
      91. /// <param name="W">int</param>
      92. /// <param name="H">int</param>
      93. /// <param name="Border">bool</param>
      94. /// <param name="C1">string</param>
      95. /// <param name="C2">string</param>
      96. /// <returns>string</returns>
      97. public static string Get
      98. (string id,
      99. bool auto,
      100. int W,
      101. int H,
      102. bool Border,
      103. string C1,
      104. string C2,
      105. int Start)
      106. {
      107. StringBuilder sb = new StringBuilder();
      108. sb.Append(@"<embed src='http://www.youtube.com/v/");
      109. // select the youTube item to play
      110. sb.Append(id);
      111. // set autoplay options (indicates number of plays)
      112. if (auto) sb.Append("&autoplay=1");
      113. // no related items to display
      114. sb.Append("&rel=0");
      115. // set border color 1 and 2
      116. if (Border)
      117. {
      118. sb.Append("&border=1");
      119. sb.Append("&color1=" + @C1);
      120. sb.Append("&color2=" + @C2);
      121. }
      122. // start position
      123. if (Start>0) sb.Append("&start=" + Start.ToString());
      124. // allow full screen
      125. sb.Append("&fs=1");
      126. // closing single quote after parameter list
      127. sb.Append("' ");
      128. sb.Append("type='application/x-shockwave-flash' ");
      129. // add id
      130. sb.Append("id='youTubePlayer" + DateTime.Now.Millisecond.ToString() + "' ");
      131. sb.Append("allowscriptaccess='never' enableJavascript ='false' ");
      132. // set parameters: allowfullscreen
      133. sb.Append("allowfullscreen='true' ");
      134. // set width
      135. sb.Append("width='" + W.ToString() + "' ");
      136. // set height
      137. sb.Append("height='" + H.ToString() + "' ");
      138. sb.Append(@"></embed>");
      139. // get final script
      140. string scr = sb.ToString();
      141. sb = null;
      142. return scr;
      143. }
      144. #endregion
      145. }
      Alles anzeigen


      am besten in ein WPF projekt :3
      Bei fragen einfach fragen ^^