External C-Libary and Events
Posted
#1
(In Topic #1033)
Regular

Here's the sample code:
Code (gambas)
- ' enum libvlc_state_t
- ' enum libvlc_video_orient_t
- ' Create And initialize a libvlc instance.
- ' Create a media for a certain file path.
- ' Create a Media Player object from a Media.
- ' Set an X Window System drawable where the media player should render its video output.
- ' Play the video file.
- ' Stop the video file
- ' Get the current movie length (in ms).
- ' Get the current movie time (in ms).
- ' Get current movie state.
- ' Toggle breaks.
- ' Release a media_player after use Decrement the reference count of a media player object.
- ' Decrement the reference count of a media descriptor object.
- ' Decrement the reference count of a libvlc instance, and destroy it if it reaches zero.
- 'Set the movie time (in ms)
- ' Initialize the VLC library
- ' Create a new multimedia object.
- m = libvlc_media_new_path(inst, "/home/user/Videos/first_vid.mp4")
- ' Create a media player
- mp = libvlc_media_player_new_from_media(m)
- ' To show the video in the "DrawingArea", we get his identifier
- ' We pass the identifier of the window, in which the video must be shown
- libvlc_media_player_set_xwindow(mp, id)
- ' Starts the execution of the video file by the media player :
- libvlc_media_player_play(mp)
- ' Repeat
- ' TextLabel1.Text = "Durata: " & Str(Time(0, 0, 0, libvlc_media_player_get_length(mp, 0)))
- ' TextLabel2.Text = "<font color=red>" & Str(Time(0, 0, 0, libvlc_media_player_get_time(mp))) & "</font>"
- ' Wait 0.01
- ' Until libvlc_media_player_get_state(mp) > libvlc_Paused
- '
- ' Chiude()
- libvlc_media_player_pause(mp)
- libvlc_media_player_stop(mp)
- 'Closes the VLC library
- libvlc_media_player_release(mp)
- libvlc_media_release(m)
- libvlc_release(inst)
Posted
Regular

The elements of the "libvlc_event_e " Enumeration appear to be intertwined :? with the "libvlc_event_attach() " function, the "libvlc_event_t " Enumeration, and a "<COLOR color="#BF0000">callback</COLOR>" loop and its specific functions.JumpyVB said
how can I hook with the events provided by the library such as libvlc_MediaPlayerTimeChanged
I have no experience with that in VLC.
Bad bargain !
…or maybe you could use a Timer.
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

vuott said
The elements of the "libvlc_event_e " Enumeration appear to be intertwined :? with the "libvlc_event_attach() " function, the "libvlc_event_t " Enumeration, and a "<COLOR color="#BF0000">callback</COLOR>" loop and its specific functions. I have no experience with that in VLC. Or maybe you could use a Timer.
Yeas a timer could do the trick. Thank you for the idea.
Also I will consider investigating further (externing events for the libvlc) myself. Making use of c libraries from Gambas has been on my todo list (despite c language seems very daunting). But do you have previous experience of interfacing some other c library with events? If you can confirm it could be possible I would know it's not a lost cause? A link to a gambas example with any extern events would help tremendously.
PS: My home videos are working fine now in libvlc as opposed to gstreamer. I am experiencing none of that non responsivenes at the end of the video.
Posted
Regular

Usually Events in C programs are handled with loops or "callbacks" calls.JumpyVB said
But do you have previous experience of interfacing some other c library with events?
For handling "callback" calls, using external resources in Gambas, you can have a look at this section "Function Callbacks" in the following official Wiki page:
/lang/extdecl - Gambas Documentation
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

Call this function before "libvlc_new(0, Null)" to get rid of error "Xlib not initialized for threads".
Source for the information was found here: https://forum.videolan.org/viewtopic.php?t=136443
Posted
Regular

Code (gambas)
- ' Gambas class file
- '# Events
- '# Get the Event Manager from which the media player send event.
- '# Register for an event notification.
- '# enum libvlc_event_e [https://github.com/videolan/libvlcsharp/blob/3.x/src/LibVLCSharp/Shared/LibVLCEvents.cs]
- Private Enum MediaMetaChanged = 0, MediaSubItemAdded = 1, MediaDurationChanged = 2, MediaParsedChanged = 3, MediaFreed = 4, MediaStateChanged = 5, MediaSubItemTreeAdded = 6, MediaPlayerMediaChanged = 256, MediaPlayerNothingSpecial = 257, MediaPlayerOpening = 258, MediaPlayerBuffering = 259, MediaPlayerPlaying = 260, MediaPlayerPaused = 261, MediaPlayerStopped = 262, MediaPlayerForward = 263, MediaPlayerBackward = 264, MediaPlayerEndReached = 265, MediaPlayerEncounteredError = 266, MediaPlayerTimeChanged = 267, MediaPlayerPositionChanged = 268, MediaPlayerSeekableChanged = 269, MediaPlayerPausableChanged = 270, MediaPlayerTitleChanged = 271, MediaPlayerSnapshotTaken = 272, MediaPlayerLengthChanged = 273, MediaPlayerVout = 274, MediaPlayerScrambledChanged = 275, MediaPlayerESAdded = 276, MediaPlayerESDeleted = 277, MediaPlayerESSelected = 278, MediaPlayerCorked = 279, MediaPlayerUncorked = 280, MediaPlayerMuted = 281, MediaPlayerUnmuted = 282, MediaPlayerAudioVolume = 283, MediaPlayerAudioDevice = 284, MediaPlayerChapterChanged = 285, MediaListItemAdded = 512, MediaListWillAddItem = 513, MediaListItemDeleted = 514, MediaListWillDeleteItem = 515, MediaListEndReached = 516, MediaListViewItemAdded = 768, MediaListViewWillAddItem = 769, MediaListViewItemDeleted = 770, MediaListViewWillDeleteItem = 771, MediaListPlayerPlayed = 1024, MediaListPlayerNextItemSet = 1025, MediaListPlayerStopped = 1026
- '# typedef void( * libvlc_callback_t)(const struct libvlc_event_t * p_event, void * p_data)
- Public Struct Libvlc_event_t
- End Struct
- XInitThreads() '# https://forum.videolan.org/viewtopic.php?t=136443
- m = libvlc_media_new_path(inst, "/home/user/Videos/first_vid.mp4")
- mp = libvlc_media_player_new_from_media(m)
- event_manager = libvlc_media_player_event_manager(mp)
- libvlc_media_player_set_xwindow(mp, id)
- libvlc_media_player_play(mp)
- libvlc_media_player_pause(mp)
Posted
Regular

Anyway, I was able to eliminate the error when clicking on the "ToggleButton" to pause the video file.
I made the following changes.
1) The Structure "Libvlc_event_t" of the VLC library contains, as a third member a "Union" that occupies 16 bytes. In the Structure, which you reproduced in Gambas, I simply declared that third member as a "Pointer".
Here it is:
2) It is also necessary to add the external function "libvlc_event_detach()" in the routine "ToggleButtonPause_Click()", when pausing the execution of the video file (it should be placed after the external function "libvlc_media_player_pause()"); as well as to call up the external function "libvlc_event_attach()". when resuming the execution of the video after pausing.
3) In addition, it was necessary to correctly arrange the command lines within the routine "Public Sub ToggleButtonPause_Click()".
4) Here is the :? new piece of code:
Code (gambas)
- .......
- ......
- XInitThreads() '# https://forum.videolan.org/viewtopic.php?t=136443
- m = libvlc_media_new_path(inst, "/path/of/video/file")
- mp = libvlc_media_player_new_from_media(m)
- event_manager = libvlc_media_player_event_manager(mp)
- libvlc_media_player_set_xwindow(mp, id)
- libvlc_media_player_play(mp)
- libvlc_media_player_pause(mp)
- libvlc_media_player_play(mp)
5) Now it works !
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

I can confirm. Thank you.vuott said
Now it works!
1 guest and 0 members have just viewed this.



