-1

I want to create a plugin that adds a video on the current slide in an open instance of Open Office Impress by specifying the location of the video automatically. I have successfully added shapes to the slide. But I cannot find a way to embed a video.

Using the .uno:InsertAVMedia I can take user input to choose a file and it works. How do I want to specify the location of the file programmatically?

CONCLUSION:

This is not supported by the API. Images and audio can be inserted without user intervention but videos cannot be done this way. Hope this feature is released in subsequent versions.

Joey Pinto
  • 1,735
  • 1
  • 18
  • 34
  • I have used a file stream reader to read the pptx file and then make modifications to it and save to a new file. – Joey Pinto Dec 29 '15 at 16:46
  • 1
    It would be better to remove the POI tag. I realize that your project uses POI, but that does not seem relevant to the question, which is about the AOO API. – Jim K Jul 12 '17 at 04:41
  • @JimK What else can I do to improve this question? I'm facing a dam question-ban because of this one. – Joey Pinto Jul 12 '17 at 07:49
  • The question looks pretty good now. However, people are unlikely to revisit it to revise their votes. Possibly the bounty will get some attention. Otherwise, you may be forced to delete the question, which would be disappointing for me as well as you. – Jim K Jul 12 '17 at 14:02
  • I'll upvote your question. – Yahya Jul 17 '17 at 12:01

2 Answers2

1

You requested information about an extension, even though the code you are using is quite different, using a file stream reader and POI.

If you really do want to develop an extension, then start with one of the Java samples. An example that uses Impress is https://wiki.openoffice.org/wiki/File:SDraw.zip.

Inserting videos into an Impress presentation can be difficult. First be sure you can get it to work manually. The most obvious way to do that seems to be Insert -> Media -> Audio or Video. However many people use links to files instead of actually embedding the file. See also https://ask.libreoffice.org/en/question/1898/how-to-embed-video-into-impress-presentation/.

If embedding is working for your needs and you want to automate the embedding by using an extension (which seems to be what your question is asking), then there is a dispatcher method called InsertAVMedia that does this.

I do not know offhand what the parameters are for the call. See https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=61127 for how to look up parameters for dispatcher calls.

EDIT

Here is some Basic code that inserts a video.

sub insert_video
    dim document   as object
    dim dispatcher as object
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    dispatcher.executeDispatch(document, ".uno:InsertAVMedia", "", 0, Array())
end sub

From looking at InsertAVMedia in sfx.sdi, it seems that this call does not take any parameters.

EDIT 2

Sorry but InsertVideo and InsertImage do not take parameters either. From svx.sdi it looks like the following calls take parameters of some sort: InsertGalleryPic, InsertGraphic, InsertObject, InsertPlugin, AVMediaToolBox.

However according to https://wiki.openoffice.org/wiki/Documentation/OOoAuthors_User_Manual/Getting_Started/Sometimes_the_macro_recorder_fails, it is not possible to specify a file for InsertObject. That documentation also mentions that you never know what will work until you try it.

InsertGraphic takes a FileName parameter, so I would think that should work.

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • The SDraw opens a new document I want to do the same in the current document – Joey Pinto Dec 30 '15 at 05:36
  • I wish to connect to a running instance of openOffice and add shapes into it – Joey Pinto Dec 30 '15 at 06:06
  • 1
    To get the current component, instead of `loadComponentFromURL`, use code like this: http://stackoverflow.com/a/32749140/5100564 – Jim K Dec 30 '15 at 06:31
  • Well I got the current component but how do I make the dispatcher method call to insert the Media – Joey Pinto Dec 30 '15 at 07:10
  • 1
    I am having difficulty finding a simple example, but you need to call the `executeDispatch` method of [XDispatchHelper](https://www.openoffice.org/api/docs/common/ref/com/sun/star/frame/XDispatchHelper.html). An example is at https://www.mail-archive.com/dev@api.openoffice.org/msg08632.html. – Jim K Dec 30 '15 at 07:45
  • 1
    The call would look something like this: `DispatchResultEvent dRE = (DispatchResultEvent) this.dispatchHelper.executeDispatch(this.dispatchProvider, ".uno:InsertAVMedia", "", 0, null);` – Jim K Dec 30 '15 at 07:50
  • I got it to work, A dialog bog pops up asking for a video to insert , But how do I automate the selection of the file and directly insert it in the document – Joey Pinto Dec 30 '15 at 10:46
  • Since `InsertAVMedia` does not take any parameters, apparently the selection must be done manually. You could automatically insert a link rather than embedding the file. – Jim K Dec 30 '15 at 17:47
  • Do InsertVideo and InsertImage take parameters. Can I use it instead. and is there any documentation available regarding the parameters to be used – Joey Pinto Dec 31 '15 at 06:21
  • Edited answer in response to these questions. – Jim K Dec 31 '15 at 08:24
  • Does impress support Macros. The call `.uno:InsertGraphic` worked in Writer but not on Impress, How do I fix that? – Joey Pinto Dec 31 '15 at 11:12
  • I am surprised to hear that, since it is listed under global dispatcher calls. But it is possible that it only works in Writer. Check your code carefully to make sure there is not a mistake. – Jim K Dec 31 '15 at 11:19
  • Theres no mistake I am sure. But Impress doesn't support Macros. Even while recording a macro to add a movie to a doc in writerr I have seen that the file doesnt get stored in the visual basic code. It does that only for pictures. So I am going to stop working and use some other workaround concluding this is not possible in impress – Joey Pinto Jan 02 '16 at 03:35
1

It is possible to add an XPlayer on the current slide. It looks like this will allow you to play a video, and you can specify the file's URL automatically.

Here is an example using createPlayer: https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=57699.

EDIT:

This Basic code works on my system. To play the video, simply call the routine.

sub play_video
    If Video_flag = 0 Then
        video =converttoURL( _
            "C:\Users\JimStandard\Downloads\H264_test1_Talkinghead_avi_480x360.avi")
        Video_flag = 1
        'for windows:
        oManager = CreateUnoService("com.sun.star.media.Manager_DirectX")
        ' for Linux
        ' oManager = CreateUnoService("com.sun.star.media.Manager_GStreamer")
        oPlayer = oManager.createPlayer( video )
        ' oPlayer.CreatePlayerwindow(array()) ' crashes?
        'oPlayer.setRate(1.1)
        oPlayer.setPlaybackLoop(False)
        oPlayer.setMediaTime(0.0)
        oPlayer.setVolumeDB(GetSoundVolume())
        oPlayer.start() ' Lecture
        Player_flag = 1
    Else
        oPlayer.start() ' Lecture
        Player_flag = 1
    End If
End Sub
Jim K
  • 12,824
  • 2
  • 22
  • 51