DocumentBuilderInsertOnlineVideo Method (String, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType) |
Namespace: Aspose.Words
public Shape InsertOnlineVideo( string videoUrl, RelativeHorizontalPosition horzPos, double left, RelativeVerticalPosition vertPos, double top, double width, double height, WrapType wrapType )
You can change the image size, location, positioning method and other settings using the Shape object returned by this method.
Insertion of online video from the following resources is supported:
If your online video is not displaying correctly, use InsertOnlineVideo(String, String, Byte, Double, Double), which accepts custom embedded html code.
The code for embedding video can vary between providers, consult your corresponding provider of choice for details.
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Visible url string vimeoVideoUrl = @"https://vimeo.com/52477838"; // Embed Html code string vimeoEmbedCode = "<iframe src=\"https://player.vimeo.com/video/52477838\" width=\"640\" height=\"360\" frameborder=\"0\" title=\"Aspose\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"; // This video will have an automatically generated thumbnail, and we are setting the size according to its 16:9 aspect ratio builder.Writeln("Video with an automatically generated thumbnail at the top left corner of the page:"); builder.InsertOnlineVideo(vimeoVideoUrl, RelativeHorizontalPosition.LeftMargin, 0, RelativeVerticalPosition.TopMargin, 0, 320, 180, WrapType.Square); builder.InsertBreak(BreakType.PageBreak); // We can get an image to use as a custom thumbnail using (WebClient webClient = new WebClient()) { byte[] imageBytes = webClient.DownloadData(AsposeLogoUrl); using (MemoryStream stream = new MemoryStream(imageBytes)) { using (Image image = Image.FromStream(stream)) { // This puts the video where we are with our document builder, with a custom thumbnail and size depending on the size of the image builder.Writeln("Custom thumbnail at document builder's cursor:"); builder.InsertOnlineVideo(vimeoVideoUrl, vimeoEmbedCode, imageBytes, image.Width, image.Height); builder.InsertBreak(BreakType.PageBreak); // We can put the video at the bottom right edge of the page too, but we'll have to take the page margins into account double left = builder.PageSetup.RightMargin - image.Width; double top = builder.PageSetup.BottomMargin - image.Height; // Here we use a custom thumbnail and relative positioning to put it and the bottom right of tha page builder.Writeln("Bottom right of page with custom thumbnail:"); builder.InsertOnlineVideo(vimeoVideoUrl, vimeoEmbedCode, imageBytes, RelativeHorizontalPosition.RightMargin, left, RelativeVerticalPosition.BottomMargin, top, image.Width, image.Height, WrapType.Square); } } } doc.Save(ArtifactsDir + "DocumentBuilder.InsertOnlineVideo.docx");