Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Add video or audio to premade presentation #1740

Open
patolax opened this issue Jun 24, 2024 · 1 comment
Open

Can't Add video or audio to premade presentation #1740

patolax opened this issue Jun 24, 2024 · 1 comment
Assignees

Comments

@patolax
Copy link

patolax commented Jun 24, 2024

Describe the bug
Can't Add video or audio to premade presentations

To Reproduce
This is my code, I load a PowerPoint presentation from disk and make text changes to the slide after I call these methods to add audio/video.

public void AddVideoToPresentation(PresentationDocument presentationDocument, string audioFilePath)
{
    int PicID = 915;
    PresentationPart presentationPart = presentationDocument.PresentationPart;
    var slideCount = presentationPart.Presentation.SlideIdList.Count();
    var videoEmbedId = string.Format("audioId{0}{1}", slideCount, PicID++);
    var mediaEmbedId = string.Format("medId{0}{1}", slideCount, PicID++);

    SlidePart slidepart = presentationDocument.PresentationPart.SlideParts.LastOrDefault();

    MediaDataPart mediaDataPart1 = presentationDocument.CreateMediaDataPart("audio/mp3", ".mp3");
    System.IO.Stream mediaDataPart1Stream = File.OpenRead(audioFilePath);
    mediaDataPart1.FeedData(mediaDataPart1Stream);
    mediaDataPart1Stream.Close();

    slidepart.AddAudioReferenceRelationship(mediaDataPart1, videoEmbedId);
    slidepart.AddMediaReferenceRelationship(mediaDataPart1, mediaEmbedId);

    slidepart.Slide.Save();

    AddVid(presentationDocument);
}


public void AddVid(PresentationDocument presentationDocument)
{
    PresentationPart presentationPart = presentationDocument.PresentationPart;
    SlidePart slidepart = presentationDocument.PresentationPart.AddNewPart<SlidePart>("rxId3");
    MediaDataPart mediaDataPart1 = presentationDocument.CreateMediaDataPart("video/mp4", ".mp4");
    System.IO.Stream mediaDataPart1Stream = System.IO.File.Open(@"D:\samplevideo.mp4", System.IO.FileMode.Open);
    mediaDataPart1.FeedData(mediaDataPart1Stream);
    mediaDataPart1Stream.Close();

    slidepart.AddMediaReferenceRelationship(mediaDataPart1, "rxId2");
    slidepart.AddVideoReferenceRelationship(mediaDataPart1, "rxId1");
}

Observed behavior
No Video or audio embedded in the presentation

Expected behavior
Play audio after slide transition

Desktop (please complete the following information):

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <UseWindowsForms>true</UseWindowsForms>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
    <PackageReference Include="Microsoft.Office.Interop.PowerPoint" Version="15.0.4420.1018" />
    <PackageReference Include="Mscc.GenerativeAI" Version="1.5.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="OpenXmlPowerTools.NetCore" Version="1.1.0" />
    <PackageReference Include="System.ServiceModel.Syndication" Version="8.0.0" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="office">
      <HintPath>..\..\..\..\..\Windows\assembly\GAC_MSIL\office\15.0.0.0__71e9bce111e9429c\OFFICE.DLL</HintPath>
    </Reference>
  </ItemGroup>

</Project>
@yswenli
Copy link

yswenli commented Jul 15, 2024

How to add video or audio to a pre made presentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants