How to check if VlcMedia contains a video?

264 Views Asked by At

I am developing a media player using vlc-qt I wanted to know how can I identify that my player contains a video or not. For example

m_player=new VlcMediaPlayer(m_instance);
m_media= new VlcMedia("",m_instance);
m_player->open(m_media);
m_player->play()

As you can see here my m_media is initialized with no video url so how can I check whether my m_media contains any video or not.

I wanted to know this because so that in my player i will control play/stop button.

2

There are 2 best solutions below

2
Minh On

According to VlcMedia source, the string you give to the class can be retrieved using the getter VlcMedia::currentLocation(). From that string, you can use QFile::exists() to check if the file path exists.

5
scopchanov On

Solution

After opening the media use VlcMediaPlayer::video to retrieve the video object and check if it is valid, i.e. not a nullptr.

Example

Here is an example I wrote for you to demonstrate a possible implementation of the proposed solution:

m_player = new VlcMediaPlayer(m_instance);
m_media = new VlcMedia("", m_instance);
m_player->open(m_media);

if (m_player->video())
    m_player->play();