Skip to main content

SlideMedia

Struct SlideMedia 

Source
pub struct SlideMedia {
    pub id: u32,
    pub name: String,
    pub data: Vec<u8>,
    pub format: MediaFormat,
    pub offset_emu: (i64, i64),
    pub extent_emu: (i64, i64),
    pub poster_image: Option<(Vec<u8>, PictureFormat)>,
}
Expand description

An embedded video or audio clip (<p:pic> carrying an <a:videoFile r:link=".">/<a:audioFile r:link="."> reference in its own <p:nvPr>, instead of the plain <a:blip> image an ordinary Picture has).

Real PowerPoint (2010+) also writes a Microsoft-proprietary <p:extLst><p:ext><p14:media r:embed=".."/></p:ext></p:extLst> alongside the core <a:videoFile>/<a:audioFile> element, referencing the same media part a second time for its own newer UI features — not modeled here (an extension outside ECMA-376 itself, same “skip Microsoft-only extensions” posture this crate already takes for <a:extLst> generally); the core relationship alone is schema-complete and should still play in real PowerPoint.

<p:timing> (autoplay/on-click trigger, bookmarks, trim points) lives at the slide level, not on the shape itself, and is a materially larger, separate feature — not modeled. Unlike Picture, this type has no shape_properties field: the writer always produces a plain default rectangle (<a:prstGeom prst="rect">, no custom fill/ line), and any non-default geometry/fill/line an existing file’s own <p:pic> might carry is simply discarded when read back — a video/audio clip’s own outline styling is a rare, cosmetic refinement didn’t ask for.

Fields§

§id: u32

<p:cNvPr id=".."> — same uniqueness rules as AutoShape::id.

§name: String

<p:cNvPr name="..">.

§data: Vec<u8>

The raw, encoded media bytes (e.g. the bytes of a .mp4 file).

§format: MediaFormat

The media’s encoding, also used to pick the media part’s extension/ content type and to tell video from audio (format.is_video()).

§offset_emu: (i64, i64)

<a:off x=".." y="..">, in EMUs — same “never optional, no separate anchor” posture as Picture::offset_emu.

§extent_emu: (i64, i64)

<a:ext cx=".." cy="..">, in EMUs.

§poster_image: Option<(Vec<u8>, PictureFormat)>

This clip’s poster frame (<p:blipFill>’s own <a:blip>, the still image real PowerPoint shows before playback) — the raw image bytes plus its format. None omits <a:blip> from <p:blipFill> entirely (schema-valid — blip is minOccurs="0" — but the clip will render with no visible thumbnail until played).

Implementations§

Source§

impl SlideMedia

Source

pub fn new( id: u32, name: impl Into<String>, data: impl Into<Vec<u8>>, format: MediaFormat, width_emu: i64, height_emu: i64, ) -> SlideMedia

Creates a media clip at the given size, positioned at (0, 0), with no poster frame.

Examples found in repository?
examples/pptx_media.rs (lines 49-56)
20fn main() -> office_toolkit::Result<()> {
21    let path = output_path("pptx_media.pptx");
22    let image_bytes = std::fs::read(image_fixture_path())?;
23
24    let embedded_picture = Picture::new(
25        2,
26        "Embedded picture",
27        image_bytes.clone(),
28        PictureFormat::Png,
29        3_000_000,
30        2_000_000,
31    )
32    .with_offset(838_200, 838_200)
33    .with_description("Project test image");
34
35    let linked_picture = Picture::new(
36        2,
37        "Externally linked picture",
38        image_bytes,
39        PictureFormat::Png,
40        3_000_000,
41        2_000_000,
42    )
43    .with_offset(838_200, 838_200)
44    .with_external_link("https://example.com/original-image.png");
45
46    // Placeholder bytes — a real .pptx would carry a genuine video file
47    // here. This example only demonstrates the model/writer plumbing.
48    let poster_image = vec![0x89, 0x50, 0x4E, 0x47]; // fake, just enough bytes to have *some* data
49    let media = SlideMedia::new(
50        2,
51        "Video clip",
52        vec![0u8; 16],
53        MediaFormat::Mp4,
54        4_000_000,
55        2_250_000,
56    )
57    .with_offset(838_200, 838_200)
58    .with_poster_image(poster_image, PictureFormat::Png);
59
60    let chart = SlideChart::new(
61        2,
62        "Quarterly revenue",
63        sample_chart_space(),
64        6_000_000,
65        3_500_000,
66    )
67    .with_offset(838_200, 838_200);
68
69    let presentation = Presentation::new()
70        .with_slide(Slide::new().with_shape(Shape::Picture(embedded_picture)))
71        .with_slide(Slide::new().with_shape(Shape::Picture(linked_picture)))
72        .with_slide(Slide::new().with_shape(Shape::Media(media)))
73        .with_slide(Slide::new().with_shape(Shape::Chart(Box::new(chart))));
74
75    presentation.save_to_file(&path)?;
76    println!("Wrote {}", path.display());
77    Ok(())
78}
Source

pub fn with_offset(self, x_emu: i64, y_emu: i64) -> SlideMedia

Sets this clip’s position.

Examples found in repository?
examples/pptx_media.rs (line 57)
20fn main() -> office_toolkit::Result<()> {
21    let path = output_path("pptx_media.pptx");
22    let image_bytes = std::fs::read(image_fixture_path())?;
23
24    let embedded_picture = Picture::new(
25        2,
26        "Embedded picture",
27        image_bytes.clone(),
28        PictureFormat::Png,
29        3_000_000,
30        2_000_000,
31    )
32    .with_offset(838_200, 838_200)
33    .with_description("Project test image");
34
35    let linked_picture = Picture::new(
36        2,
37        "Externally linked picture",
38        image_bytes,
39        PictureFormat::Png,
40        3_000_000,
41        2_000_000,
42    )
43    .with_offset(838_200, 838_200)
44    .with_external_link("https://example.com/original-image.png");
45
46    // Placeholder bytes — a real .pptx would carry a genuine video file
47    // here. This example only demonstrates the model/writer plumbing.
48    let poster_image = vec![0x89, 0x50, 0x4E, 0x47]; // fake, just enough bytes to have *some* data
49    let media = SlideMedia::new(
50        2,
51        "Video clip",
52        vec![0u8; 16],
53        MediaFormat::Mp4,
54        4_000_000,
55        2_250_000,
56    )
57    .with_offset(838_200, 838_200)
58    .with_poster_image(poster_image, PictureFormat::Png);
59
60    let chart = SlideChart::new(
61        2,
62        "Quarterly revenue",
63        sample_chart_space(),
64        6_000_000,
65        3_500_000,
66    )
67    .with_offset(838_200, 838_200);
68
69    let presentation = Presentation::new()
70        .with_slide(Slide::new().with_shape(Shape::Picture(embedded_picture)))
71        .with_slide(Slide::new().with_shape(Shape::Picture(linked_picture)))
72        .with_slide(Slide::new().with_shape(Shape::Media(media)))
73        .with_slide(Slide::new().with_shape(Shape::Chart(Box::new(chart))));
74
75    presentation.save_to_file(&path)?;
76    println!("Wrote {}", path.display());
77    Ok(())
78}
Source

pub fn with_poster_image( self, data: impl Into<Vec<u8>>, format: PictureFormat, ) -> SlideMedia

Sets this clip’s poster frame image.

Examples found in repository?
examples/pptx_media.rs (line 58)
20fn main() -> office_toolkit::Result<()> {
21    let path = output_path("pptx_media.pptx");
22    let image_bytes = std::fs::read(image_fixture_path())?;
23
24    let embedded_picture = Picture::new(
25        2,
26        "Embedded picture",
27        image_bytes.clone(),
28        PictureFormat::Png,
29        3_000_000,
30        2_000_000,
31    )
32    .with_offset(838_200, 838_200)
33    .with_description("Project test image");
34
35    let linked_picture = Picture::new(
36        2,
37        "Externally linked picture",
38        image_bytes,
39        PictureFormat::Png,
40        3_000_000,
41        2_000_000,
42    )
43    .with_offset(838_200, 838_200)
44    .with_external_link("https://example.com/original-image.png");
45
46    // Placeholder bytes — a real .pptx would carry a genuine video file
47    // here. This example only demonstrates the model/writer plumbing.
48    let poster_image = vec![0x89, 0x50, 0x4E, 0x47]; // fake, just enough bytes to have *some* data
49    let media = SlideMedia::new(
50        2,
51        "Video clip",
52        vec![0u8; 16],
53        MediaFormat::Mp4,
54        4_000_000,
55        2_250_000,
56    )
57    .with_offset(838_200, 838_200)
58    .with_poster_image(poster_image, PictureFormat::Png);
59
60    let chart = SlideChart::new(
61        2,
62        "Quarterly revenue",
63        sample_chart_space(),
64        6_000_000,
65        3_500_000,
66    )
67    .with_offset(838_200, 838_200);
68
69    let presentation = Presentation::new()
70        .with_slide(Slide::new().with_shape(Shape::Picture(embedded_picture)))
71        .with_slide(Slide::new().with_shape(Shape::Picture(linked_picture)))
72        .with_slide(Slide::new().with_shape(Shape::Media(media)))
73        .with_slide(Slide::new().with_shape(Shape::Chart(Box::new(chart))));
74
75    presentation.save_to_file(&path)?;
76    println!("Wrote {}", path.display());
77    Ok(())
78}

Trait Implementations§

Source§

impl Clone for SlideMedia

Source§

fn clone(&self) -> SlideMedia

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SlideMedia

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for SlideMedia

Source§

fn eq(&self, other: &SlideMedia) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SlideMedia

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.