<html><head></head><body>Why not merge is_playing and get_position in one single loop?<br><br><div class="gmail_quote"><br>
Felix Abecassis <felix.abecassis@gmail.com> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">Avoid waiting unnecessarily when the media player reaches exactly THUMBNAIL_POSITION. However we must now wait until libvlc updates the position before polling with libvlc_media_player_get_position().<br />---<br />vlc-android/jni/thumbnailer.c | 15 +++++++++++----<br />1 file changed, 11 insertions(+), 4 deletions(-)<br /><br />diff --git a/vlc-android/jni/thumbnailer.c b/vlc-android/jni/thumbnailer.c<br />index 2d41a59..4086612 100644<br />--- a/vlc-android/jni/thumbnailer.c<br />+++ b/vlc-android/jni/thumbnailer.c<br />@@ -263,12 +263,19 @@ jbyteArray Java_org_videolan_libvlc_LibVLC_getThumbnail(JNIEnv *env, jobject thi<br />libvlc_media_player_play(mp);<br />libvlc_media_player_set_position(mp, THUMBNAIL_POSITION);<br /><br />- int loops = 100;<br />- for (;;) {<br />+ int wait_time = 50000;<br />+ int max_attempts = 100;<br />+ for (int i = 0; i < max_attempts; ++i) {<br />+ int playing = libvlc_media_player_is_playing(mp);<br />+
if (playing)<br />+ break;<br />+ usleep(wait_time);<br />+ }<br />+ for (int i = 0; i < max_attempts; ++i) {<br />float pos = libvlc_media_player_get_position(mp);<br />- if (pos > THUMBNAIL_POSITION || !loops--)<br />+ if (pos >= THUMBNAIL_POSITION)<br />break;<br />- usleep(50000);<br />+ usleep(wait_time);<br />}<br /><br />/* Wait for the thumbnail to be generated. */</pre></blockquote></div><br>
-- <br>
Envoyé de mon téléphone Android avec K-9 Mail. Excusez la brièveté.</body></html>