Play video from basic macro

How to play a video from basic? This works for an audio file:

        oPlayer = oAVMgr.createPlayer(sFile)
        oPlayer.setPlaybackLoop(False)
        oPlayer.setMediaTime(0.0)
        iLevel=6
        oPlayer.setVolumeDB(iLevel)
        oPlayer.start(0)

With a video file, sound is audible, but no video. So I presume I need oPlayer.CreatePlayerWindow(…), but I have not a clue how to use it. The documentation at XPlayer Interface Reference is pretty opaque to me. Any help welcome.

Ubuntu 22-04 LO24.2.5.2

2024 July 24

I have the same problem. No solution found, for myself and in the forum.
The issue should be addressed in the help file, I think.
Any help welcome.

1 Like

… how do you get the oAVMgr ?

@ms777 Like this:
oAVMgr = CreateUnoService(“com.sun.star.comp.media.Manager_GStreamer”)

… cool. After 20y+ with OO I am still learning new services …
This works for me on Windows 10:

oAVMgr = CreateUnoService("com.sun.star.media.Manager_DirectX")
oPlayer = oAVMgr.createPlayer(ConvertToUrl("C:\Users\Martin\Desktop\1811076_1024x576_H264_HQ.mp4"))
oPlayer.start()
wait 5000
oPlayer.stop()
1 Like

Thanks for your reply @ms777. I am amazed to think I have also been using OO or LO for 20 yrs, but still feel like a newbie. Your code appears similar to mine which produces sound ok. Did yours work for video? because mine does not seem to. Incidentally, without .comp in the createUnoService statement, Ubuntu does not start the media manager. (I’ve edited the question to include OS and versions.)

Hallo
Ubuntu? simply use python with subprocess:

from subprocess import run
run(['vlc', '~/path/to/videofile.mp4'])

also see python subprocess Dokumentation and

cvlc --help

Can you play the video outside LibreOffice? All necessary codecs abailable? (I’m not familiar with current Ubuntu-installs.)

Yes, it plays with video. I also suspect it has something to do with the drivers installed on your system, see e.g. Playing Embedded Videos? for this on Windows.

For com.sun.star.comp.media.Manager_GStreamer vs com.sun.star.media.Manager_GStreamer see Apache OpenOffice Community Forum - [Solved] Calc Macro to play an MP3 Audio File. - (View topic)

Thanks @karolus . My current solution, like this, is to spawn VLC, but from basic (I don’t know python). It works, but I wanted to use the internal media player, largely out of curiosity.

Yes, @Wanderer, it all works outside LO and I can spawn VLC from within LO and play videos.

Thanks again, @ms777 . Your second reference is where I discovered the .comp trick. Your first reference seems very Windows oriented. However, if yours works and my sound works, I think there must be a missing driver or codec of some sort.

As vlc brings usually everything needed itself, this would not proof a working install of gstreamer. Something missing or to repair here seems to be a common problem:

.
Maybe try gst-inspect:
https://gstreamer.freedesktop.org/documentation/tutorials/basic/gstreamer-tools.html?gi-language=c

It looks like the (Windows) service com.sun.star.media.Manager_DirectX is undocumented. The cross-platform service is com.sun.star.media.Manager, but apparently there is a bug that prevents it from being created using CreateUnoService. 161387 – Can't create instance of com.sun.star.media.Manager

Thanks @Wanderer. I hadn’t appreciated that vlc uses internal mechanisms. All the packages referred to in your first 2 links are installed already. However the tutorial has a larger install list, which installed several more packages. It has not altered the problem. I’m currently working through the tutorial. I am unclear what to inspect with gst-inspect. It does not open the video file, but returns ‘invalid ELF header’.