Replace a Video in a Slide of PowerPoint Presentation Using Aspose.Slides for .NET

Hi
How to replace a video in a Slide please ? Is it even possible ?
Thank you !

@pcaillol,
Thank you for posting the question.

Could you please describe in more detail the problem you are facing? It would be great if you could share a presentation file and describe the expected result you want to achieve with Aspose.Slides.

Hi Andrey i was finally able to achieve it, thank you !

The question now is where to set “Show the media controls” in “SlideShowSettings”, i have SlideShowType, ShowAnimation, ShowNarration, UseTimings, Slides but not “Show the media controls”.

I think you did not add that setting, am i correct ?

here is documentation: Set the 'play' options for a video in your presentation - Microsoft Support.

Thank you

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESNET-43744

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

hi
For precision: the idea is to keep all animations and effects properties previously configured when replacing the video.
All that in one function.
How long do you think for that please ?
regards

@pcaillol,
Please share an example of input and output presentations created in PowerPoint to better understand your requirements.

Hi

https://we.tl/t-yLGKzcC54c

here are in and out files: i have replaced manually both videos source files BUT animations and order are not kept identical.

That is the reason why i am asking you a new function to replace a video source file without removing/adding VideoFrame that would keep every property about the shape, do you understand ?

Thank you

@pcaillol,
Could you please share the simplest complete code example that reproduces the problem you described?

IVideoFrame vf = shape as IVideoFrame;

try
{
    newvid_s = File.OpenRead(newvid);

    //ReadStreamAndRelease causes outofmemoryexception
    IVideo vid = pres.Videos.AddVideo(newvid_s, LoadingStreamBehavior.KeepLocked);

    if (vid != null)
    {
        //warning sometimes !
        // Add Video Frame: causes exception "La méthode ou l'opération n'est pas implémentée."
        IVideoFrame newvf = slide.Shapes.AddVideoFrame(vf.Frame.X, vf.Frame.Y, vf.Frame.Width, vf.Frame.Height, vid);

        // Set Poster Image                          
        var vidposter = EasyEmbedVideoToPPT.Tools.Video.GetVideoPoster(newvid);

        //extraction success
        if (File.Exists(vidposter))
        {
            using (var imageStream = File.OpenRead(vidposter))
            {
                newvf.PictureFormat.Picture.Image = pres.Images.AddImage(imageStream);
            }
            try
            {
                File.Delete(vidposter);
            }
            catch (Exception ex)
            {
                OnWriteLog(new WriteLogEventArgs("Can't delete: " + vidposter, LogType.success));
            }
        }
        else
        {
            OnWriteLog(new WriteLogEventArgs("Could not extract poster of video: " + newvid, LogType.info));
        }

        //duplicate vid properties
        UpdateVideoFrame(vf, ref newvf, media);

        //update animations
        //UpdateVideoAnimations(vf, ref newvf);

        //removes physical video in pptx and shape at same time
        slide.Shapes.Remove(shape);

        OnWriteLog(new WriteLogEventArgs("Replacing video SUCCESS: " + newvid_withoutextension, LogType.success));
    }
}
catch (Exception ex)
{
    OnWriteLog(new WriteLogEventArgs("Could not replace video: " + ex.Message, LogType.erreur));
}

@pcaillol,
Unfortunately, I was unable to replace the video keeping all animations and effects.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESNET-43764

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@pcaillol,
Our developers have investigated the case. You can add a new video to the presentation and replace the embedded video with the new one without removing the VideoFrame object. The following code example shows you how to do this:

using (var presentation = new Presentation("IN.pptx"))
{
    var vFrame = presentation.Slides[0].Shapes[1] as VideoFrame;

    using (var newVideoStream = File.OpenRead("video3.mp4"))
    {
        var newVideo = presentation.Videos.AddVideo(newVideoStream, LoadingStreamBehavior.KeepLocked);

        // Replace the embedded video.
        vFrame.EmbeddedVideo = newVideo;

        // Set a new poster image.  
        var newImage = presentation.Images.AddImage(File.ReadAllBytes("poster3.jpg"));
        vFrame.PictureFormat.Picture.Image = newImage;

        // Rename the VideoFrame if necessary.
        vFrame.Name = "Video Name";

        presentation.Save("output.pptx", SaveFormat.Pptx);
    }
}

API Reference: IVideoFrame interface

Hi Andrey
Oh as simple as it is ! That’s great ! Big thanks. Cheers

@pcaillol,
Thank you for your feedback.

How long do you think that fix will take to be released please ?
thank you

@pcaillol,
I requested plans for the issues from our development team. We will let you know ASAP.

The issues you found earlier (filed as SLIDESNET-43744) have been fixed in Aspose.Slides for .NET 23.8 (ZIP, MSI).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.

@pcaillol,
With Aspose.Slides for .NET 23.8, you can manage the Show Media Controls option like this:

presentation.SlideShowSettings.ShowMediaControls = true;