Python VLC MediaPlayer – Getting Cursor
In this article we will see how we can get the cursor position in the MediaPlayer object in the python vlc module. VLC media player is a free and open-source portable cross-platform media player software and streaming media server developed by the VideoLAN project. MediPlyer object is the basic object in vlc module for playing the video. We can create a MediaPlayer object with the help of MediaPlayer
method. Mouse pointer coordinates over a video are expressed as 2-tuple (x, y). Coordinates are expressed in terms of the decoded video resolution, not in terms of pixels on the screen/viewport.
In order to do this we will use
video_get_cursor
method with the MediaPlayer objectSyntax : media_player.video_get_cursor()
Argument : It takes no argument
Return : It returns tuple
Below is the implementation
# importing vlc module import vlc # importing time module import time # creating vlc media player object media_player = vlc.MediaPlayer() # media resource locator mrl = "death_note.mkv" # setting mrl to the media player media_player.set_mrl(mrl) # start playing video media_player.play() # wait so the video can be played for 5 seconds # irrespective for length of video time.sleep( 5 ) # getting cursor co-ordinates value = media_player.video_get_cursor() # printing cursor co-ordinates print ( "Cursor Co-ordinates : " ) print (value) |
Output :
Cursor Co-ordinates : (655, 436)
Another example
Below is the implementation
# importing vlc module import vlc # importing time module import time # creating vlc media player object media_player = vlc.MediaPlayer() # media resource locator mrl = "1.mp4" # setting mrl to the media player media_player.set_mrl(mrl) # start playing video media_player.play() # wait so the video can be played for 5 seconds # irrespective for length of video time.sleep( 5 ) # getting cursor co-ordinates value = media_player.video_get_cursor() # printing cursor co-ordinates print ( "Cursor Co-ordinates : " ) print (value) |
Output :
Cursor Co-ordinates : (607, 267)
Please Login to comment...