[]
        
(Showing Draft Content)

Online Video

GcWord allows you to insert and play online videos directly from the document without leaving the document. You can add an online video to the document by inserting the URL of the video into the picture created with Picture class using SetUrl method of WebVideoProperties class.

SetUrl method has three overloads, allowing users to specify the input URL, title, height, and width of the video. This method generates the appropriate EmbeddedHtml property string internally, providing a convenient way for users to define these parameters that may be challenging to write directly.

Note: EmbeddedHtml property will receive width and height either from parameters or directly from Width and Height properties of WebVideoProperties class when the user uses an overload without them. EmbeddedHtml, Width, and Height properties are serialized as distinct OpenXML tags.

Refer to the following example code to insert the URL of the video to add online video to the document:

// Initialize GcWordDocument.
var doc = new GcWordDocument();

// Add picture to document.
var image = doc.Body.Paragraphs.Add().AddRun().AddPicture();
            
// Set poster frame image.
byte[] imageBytes1 = File.ReadAllBytes("sunrise.jpg");
image.ImageData.SetImage(imageBytes1, contentType: "image/jpg");

// Add online video Url and set title, width, and height.
image.ImageData.WebVideoProperties.SetUrl("https://www.youtube.com/watch?v=gsnqXt7d1mU&list=PL4Gr5tOAPttLOY9IrWVjJlv4CtkYI5cI_&index=2", "Sunrise", 600, 300);

// Save the document.
doc.Save("OnlineVideo.docx");

online-video

Limitations

Microsoft Word ignores the parameters of SetUrl method (width, height, and title) and Width and Height properties. The effects of these parameters and properties may be visible in alternative applications that also work with Word files.