embed video using just url

2020-07-09 02:42发布

问题:

given a youtube url, how can i embed the video into a page using .net c#?

回答1:

In ASP.NET MVC 3 you could use the Video.Flash method from the ASP.NET Web Pages Helpers:

@Microsoft.Web.Helpers.Video.Flash("http://www.youtube.com/v/xxxxxx")

Here is a worthwile blog post explaining how you could implement it:

  • Video Web Helper in ASP.NET MVC 3 RC 2 - Add Videos to your Web Pages

Update

If you don't want to use Microsoft's Web Pages Helpers you can of course write your own HtmlHelper extension method. You can find a good downloadable example for a HtmlHelper to display YouTube videos in ASP.NET MVC in this blog post:

  • Display youtube video in asp.net mvc using "YouTubePlayerHelper"


回答2:

Simply add in a line like the following

<iframe type="text/html" width="640" height="385" src="http://www.youtube.com/embed/[VIDEO_ID]?autoplay=1" frameborder="0">
</iframe>

With the autoplay= set as you like to either 0 or 1 (depending on whether you want people to actually stay on your page or not :)



回答3:

You can try with HTML 5's video tag:

 <video id="SomeID" name="media" src="http://youtube.com/somevideo" />