Hi,all!
In my pragram, I used the vlc to make a media player.
I use the libvlc_event_attach to receive the event emit from vlc library,code as below:
void VLCMediaPlayerPrivate::setMedia(const QMediaContent &media)
{
QString mrl = media.canonicalUrl().toString();
m_vlcMedia = libvlc_media_new_path( m_vlcInstance, mrl.toAscii());
if (m_vlcMedia) {
libvlc_event_manager_t *vlcEventManager = libvlc_media_event_manager(m_vlcMedia);
if (vlcEventManager) {
libvlc_event_attach(vlcEventManager, libvlc_MediaDurationChanged, durationChanged, this);
}
}
// Put the media into the mediaplayer
libvlc_media_player_set_media( m_vlcMediaPlayer, m_vlcMedia);
}
durationChanged is a static member function of class VLCMediaPlayerPrivate,and I passed the this pointer as user data to the libvlc_event_attach.And the durationChanged implements:
void VLCMediaPlayerPrivate::durationChanged(const struct libvlc_event_t *event, void *data)
{
if (data) {
VLCMediaPlayerPrivate* pthis = (VLCMediaPlayerPrivate*)data;
if (event->type == libvlc_MediaDurationChanged)
pthis->emitDurationChanged(static_cast<qint64>(event->u.media_duration_changed.new_duration));
}
}
emitDurationChanged is a non-static member function to emit a qt singals as belows:
void VLCMediaPlayerPrivate::emitDurationChanged(qint64 duration)
{
Q_Q(VLCMediaPlayer);
m_duration = duration;
Q_EMIT q->durationChanged(m_duration);
}
But I can’t receive the durationChanged single, seems not working, this is why?
↧