libvlc_media_get_duration return -1. But if I play the file using VlcPlayer it's duration is shown okay. Is there any way to get file duration without playing it?
This is due to the fact that the item is not parsed by default.
You can for libvlc to parse it with libvlc_media_parse or libvlc_media_parse_async (asynchronous call). You can check if a media is parsed with libvlc_media_is_parsed.