[vlc-commits] [Git][videolan/vlc][master] libvlc_media: expose duration if it is known regardless of parsing state
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Sun Aug 30 08:07:14 UTC 2026
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
3d053547 by Felix Paul Kühne at 2026-08-30T09:54:42+02:00
libvlc_media: expose duration if it is known regardless of parsing state
Certain playlist parsers such as podcast know the duration of a media
even if the media itself was not parsed or played yet.
- - - - -
2 changed files:
- include/vlc/libvlc_media.h
- lib/media.c
Changes:
=====================================
include/vlc/libvlc_media.h
=====================================
@@ -527,12 +527,12 @@ libvlc_media_subitems( libvlc_media_t *p_md );
/**
* Get duration (in us) of media descriptor object item.
*
- * Note, you need to parse using libvlc_parser_queue() or play the media
- * at least once before calling this function.
- * Not doing this will result in an undefined result.
+ * The duration is known if the media was parsed using libvlc_parser_queue(),
+ * played at least once, or created by a source that already advertises it,
+ * such as a playlist carrying duration metadata.
*
* \param p_md media descriptor object
- * \return duration of media item or -1 on error
+ * \return duration of media item or -1 if it is unknown
*/
LIBVLC_API libvlc_time_t
libvlc_media_get_duration( libvlc_media_t *p_md );
=====================================
lib/media.c
=====================================
@@ -545,10 +545,12 @@ libvlc_media_get_duration( libvlc_media_t * p_md )
return -1;
}
- if (!input_item_IsPreparsed( p_md->p_input_item ))
+ vlc_tick_t i_duration = input_item_GetDuration( p_md->p_input_item );
+
+ if( i_duration == 0 && !input_item_IsPreparsed( p_md->p_input_item ) )
return -1;
- return libvlc_time_from_vlc_tick(input_item_GetDuration( p_md->p_input_item ));
+ return libvlc_time_from_vlc_tick( i_duration );
}
int
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/3d0535473f940b38cb2b425ecfb396b1624bbb6d
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/3d0535473f940b38cb2b425ecfb396b1624bbb6d
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list