Open ajeshp opened 6 years ago
Hmm, interesting. I think this is a result of the mp3 "file" ("part" in this context) not being loaded as a MediaPart object.
The mappings that control that are here: https://github.com/scanny/python-pptx/blob/master/pptx/__init__.py#L27
As you'll see, there's no entry for CT.MP3
or any other audio formats.
You can remedy that with this code, which must be run before you load your presentation:
from pptx.opc.package import PartFactory
from pptx.parts.media import MediaPart
PartFactory.part_type_for.update(
{
'audio/mp3': MediaPart
}
)
The MIME-type ('audio/mp3' in this example) will need to exactly match the type attributed to your MP3 file in the [Content_Types].xml part of your template package (.pptx file).
I'm not sure if that will fix everything, but it should at least move you to the next error.
If you want to do the research and assemble the content types for audio files that PowerPoint supports I can add that into the next release. I've got one in the hopper here and should be publishing it in a few days.
Yes, that's all that was required. Thank You!! The MIME-type was 'audio/mpeg' in the [Content_Types].xml file, so used that. I will try to get you the content types for audio files that Powerpoint supports.
@scanny Could you please give an example of how to add an mp3 into a slide?
ppt_filename="data/test.pptx"
movie_file=["data/test/temp_000.mp3","data/test/temp_001.mp3"]
prs = Presentation(ppt_filename)
for index, slide in enumerate(prs.slides):
notes_slide = slide.notes_slide
shapes = slide.shapes
movie = shapes.add_movie(movie_file[index],
100, 100, 400, 400,
poster_frame_image=None,
mime_type='audio/mp3')
prs.save('data/test2.pptx')
It works. However, the sound clips are zero width and zero height in powerpoint. and, how can I make them autoplay?
ppt_filename="data/test.pptx"
movie_file=["data/test/temp_000.mp3","data/test/temp_001.mp3"]
prs = Presentation(ppt_filename)
left = top = width = height = Inches(1.0)
for index, slide in enumerate(prs.slides):
notes_slide = slide.notes_slide
shapes = slide.shapes
movie = shapes.add_movie(movie_file[index],
left , top , width , height,
poster_frame_image=None,
mime_type='video/unknown')
prs.save('data/test2.pptx')
I get it. the size must have an unit
@goldengrape : You helped a ton. I was looking for this answer all around.
Any possible to set the movie shape auto run?
I think I discovered an issue
Since we cannot add mp3 media using the pptx library, I added a layout with what I wanted and a mp3 media. Once I do this, when I tried to add a mp4 video, I get the below error. This is easily reproduced. The error goes away once you delete the mp3 media for the slide layout.:
Thanks, -Ajesh