player: Update media type when it is unknown
authorHugo Beauzée-Luyssen <hugo@beauzee.fr>
Tue, 26 Nov 2019 15:13:32 +0000 (16:13 +0100)
committerHugo Beauzée-Luyssen <hugo@beauzee.fr>
Thu, 9 Jan 2020 15:25:58 +0000 (16:25 +0100)
src/player/medialib.c

index 1d2665c..27f51b6 100644 (file)
@@ -129,6 +129,24 @@ end_of_media(struct vlc_player_input *input)
         input->length - input->time < VLC_TICK_FROM_SEC(end_of_media_sec);
 }
 
+static bool
+vlc_player_UpdateMediaType(const struct vlc_player_input* input,
+                           vlc_medialibrary_t* ml, vlc_ml_media_t* media)
+{
+    assert(media->i_type == VLC_ML_MEDIA_TYPE_UNKNOWN);
+    vlc_ml_media_type_t media_type;
+    if (input->video_track_vector.size > 0)
+        media_type = VLC_ML_MEDIA_TYPE_VIDEO;
+    else if (input->audio_track_vector.size > 0)
+        media_type = VLC_ML_MEDIA_TYPE_AUDIO;
+    else
+        return false;
+    if (vlc_ml_media_set_type(ml, media->i_id, media_type) != VLC_SUCCESS)
+        return false;
+    media->i_type = media_type;
+    return true;
+}
+
 void
 vlc_player_UpdateMLStates(vlc_player_t *player, struct vlc_player_input* input)
 {
@@ -154,6 +172,13 @@ vlc_player_UpdateMLStates(vlc_player_t *player, struct vlc_player_input* input)
             return;
     }
 
+    if (media->i_type == VLC_ML_MEDIA_TYPE_UNKNOWN)
+    {
+        if (!vlc_player_UpdateMediaType(input, ml, media))
+            return;
+    }
+    assert(media->i_type != VLC_ML_MEDIA_TYPE_UNKNOWN);
+
     /* If we reached end of the media, bump the play count & the media in the
      * history */
     if (end_of_media(input))