Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

player.get_lenght() doesn't give the right value. #71

Closed
jspking opened this issue Jan 31, 2019 · 3 comments
Closed

player.get_lenght() doesn't give the right value. #71

jspking opened this issue Jan 31, 2019 · 3 comments

Comments

@jspking
Copy link

jspking commented Jan 31, 2019

Hi, I just started to use python-vlc to implement video playing in my application.

I want to know the length (play time) of a video file. My function looks like below.
self.media is set properly and also I see the video playing. There is a print function in the middle playVideo function. It prints -1 even though there is no problem with playing it.
One strange thing is that some time after I call playVideo(), get_length() returns a right value(play time). Why get_length()'s return value is different?
`

def playVideo(self):
    if self.hasVideo():
        self.player.set_media(self.media)
        if platform.system() == 'Windows':
            self.player.set_hwnd(self.winfo_id())
        else:
            self.player.set_xwindow(self.winfo_id())
        self.player.play()
        print("VLC has video file %d"%self.player.get_length())
        return self.player.get_length()
    else:
        print("VLC media is None...")
        return 0
def mouse_cb(self, event):
    print("movie length: %d, time: %d"%(self.player.get_length(), self.player.get_time()))

`

@oaubert
Copy link
Owner

oaubert commented Jan 31, 2019

The play command launches the playing, which starts by trying to parse the media. But there is a slight delay due to the building of the decoding pipeline, and the play command is asychronous (it returns immediately). So the next command (get_length) does not yet have the information.

You have 2 options: either you check the is_parsed status of the media, and wait for it to become True (easy to implement, but not very clean solution) or you register a handle to the EventType.MediaParsedChanged event, which will get called when the media is actually parsed.

@oaubert oaubert closed this as completed Jan 31, 2019
@jspking
Copy link
Author

jspking commented Feb 1, 2019

Wow there was a reason why the function returns with different values!!

I just fixed my application to work properly.

Thank you.

@mrJean1
Copy link
Collaborator

mrJean1 commented Feb 1, 2019

Just a comment, methods MediaPlayer.get_length() and Media.get_duration() seem to return the same value (in millisecs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants