playmus.c: add more information printing
authorVitaly Novichkov <admin@wohlnet.ru>
Mon, 23 Dec 2019 14:01:02 +0300
changeset 112171510d620652
parent 1120 57a746548d9e
child 1122 6bf0bc6d510c
playmus.c: add more information printing

- Meta-tags if available
- Loop points if available
- Current position streaming if possible
playmus.c
     1.1 --- a/playmus.c	Mon Dec 23 14:01:02 2019 +0300
     1.2 +++ b/playmus.c	Mon Dec 23 14:01:02 2019 +0300
     1.3 @@ -118,6 +118,13 @@
     1.4      int rwops = 0;
     1.5      int i;
     1.6      const char *typ;
     1.7 +    const char *tag_title = NULL;
     1.8 +    const char *tag_artist = NULL;
     1.9 +    const char *tag_album = NULL;
    1.10 +    const char *tag_copyright = NULL;
    1.11 +    double loop_start, loop_end, loop_length, current_position;
    1.12 +
    1.13 +    (void) argc;
    1.14  
    1.15      /* Initialize variables */
    1.16      audio_rate = MIX_DEFAULT_FREQUENCY;
    1.17 @@ -250,14 +257,47 @@
    1.18          }
    1.19          SDL_Log("Detected music type: %s", typ);
    1.20  
    1.21 +        tag_title = Mix_GetMusicTitleTag(music);
    1.22 +        if (tag_title && SDL_strlen(tag_title) > 0) {
    1.23 +            SDL_Log("Title: %s", tag_title);
    1.24 +        }
    1.25 +
    1.26 +        tag_artist = Mix_GetMusicArtistTag(music);
    1.27 +        if (tag_artist && SDL_strlen(tag_artist) > 0) {
    1.28 +            SDL_Log("Artist: %s", tag_artist);
    1.29 +        }
    1.30 +
    1.31 +        tag_album = Mix_GetMusicAlbumTag(music);
    1.32 +        if (tag_album && SDL_strlen(tag_album) > 0) {
    1.33 +            SDL_Log("Album: %s", tag_album);
    1.34 +        }
    1.35 +
    1.36 +        tag_copyright = Mix_GetMusicCopyrightTag(music);
    1.37 +        if (tag_copyright && SDL_strlen(tag_copyright) > 0) {
    1.38 +            SDL_Log("Copyright: %s", tag_copyright);
    1.39 +        }
    1.40 +
    1.41 +        loop_start = Mix_GetMusicLoopStartTime(music);
    1.42 +        loop_end = Mix_GetMusicLoopEndTime(music);
    1.43 +        loop_length = Mix_GetMusicLoopLengthTime(music);
    1.44 +
    1.45          /* Play and then exit */
    1.46          SDL_Log("Playing %s, duration %f\n", argv[i], Mix_MusicDuration(music));
    1.47 +        if (loop_start > 0.0 && loop_end > 0.0 && loop_length > 0.0) {
    1.48 +            SDL_Log("Loop points: start %g s, end %g s, length %g s\n", loop_start, loop_end, loop_length);
    1.49 +        }
    1.50          Mix_FadeInMusic(music,looping,2000);
    1.51          while (!next_track && (Mix_PlayingMusic() || Mix_PausedMusic())) {
    1.52              if(interactive)
    1.53                  Menu();
    1.54 -            else
    1.55 +            else {
    1.56 +                current_position = Mix_GetMusicPosition(music);
    1.57 +                if (current_position >= 0.0) {
    1.58 +                    printf("Position: %g seconds             \r", current_position);
    1.59 +                    fflush(stdout);
    1.60 +                }
    1.61                  SDL_Delay(100);
    1.62 +            }
    1.63          }
    1.64          Mix_FreeMusic(music);
    1.65          music = NULL;