Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am creating an automation for creating power point presentation using VSTO and C#. I have create a slide show (with background music). Now I have to export this slide show to a video file. I have successfully create video, but it doesn't have the sound effect.

I write code like this:

C#
void createPPT()
{
       using PowerPoint = Microsoft.Office.Interop.PowerPoint;


       PowerPoint.Application objApp;
       PowerPoint.Presentations objPresSet;
       PowerPoint._Presentation objPres;
       PowerPoint.Slides objSlides;
       PowerPoint._Slide objSlide;
       PowerPoint.TextRange objTextRng;
       PowerPoint.Shapes objShapes;
       PowerPoint.Shape objShape;
       PowerPoint.SlideShowWindows objSSWs;
       PowerPoint.SlideShowTransition objSST;
       PowerPoint.SlideShowSettings objSSS;
       PowerPoint.SlideRange objSldRng;



        objApp = new PowerPoint.Application();
        objPresSet = objApp.Presentations;
        objPres = objPresSet.Open(strStrTemplate, MsoTriState.msoFalse,
               MsoTriState.msoTrue, MsoTriState.msoFalse);
        objSlides = objPres.Slides;

        for (int i = 0; i < SlideList.Count; ++i)
        {
        objSlide = objSlides.Add(i + 1, PowerPoint.PpSlideLayout.ppLayoutBlank);
        objSlide.Shapes.AddPicture(StrImagePath, MsoTriState.msoFalse, MsoTriState.msoTrue, 5, 5, 950, 530);


            objSldRng = objSlides.Range(i + 1);
            objSST = objSldRng.SlideShowTransition;
            objSST.AdvanceOnTime = MsoTriState.msoTrue;
            objSST.AdvanceTime = 5;
         }

            objSldRng = objSlides.Range(1);
            objSST.SoundEffect.ImportFromFile(@"D:\Songs\BGM1.wav");
            objSST.LoopSoundUntilNext = MsoTriState.msoTrue;

            //objSST.SoundEffect.Play();

            //Run Slide show - this will have audio effect
            objSSS.Run();


            //Save video file --this will not have the background music
            objPres.CreateVideo(strSavePath, true, 0,640, 60, 100);

}



Please help me to create video with background music.
Also, This code work with only .wav files. Can I use other sound formates also??

Thanks in advance..
Posted
Updated 28-Oct-15 19:49pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900