diff options
Diffstat (limited to 'moc_library.c')
-rw-r--r-- | moc_library.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/moc_library.c b/moc_library.c index 1e382aa..a76d5aa 100644 --- a/moc_library.c +++ b/moc_library.c @@ -108,6 +108,15 @@ char *get_str (int sock); int send_int (int sock, int i); int get_int (int sock, int *i); + +void reset_data(struct moc *data) { + data->filename = NULL; + data->title = NULL; + data->album = NULL; + data->artist = NULL; + data->time = -1; +} + static char *get_curr_file (const int sock) { send_int (sock, CMD_GET_SNAME); int ev; @@ -309,17 +318,21 @@ void *moc_loop(void *input) { get_int(srv_sock, &state); update_state(data, state); - char *file = get_curr_file(srv_sock); - fprintf(stderr, "moc: current file %s\n", file); - // if it's the same file as we had, don't update. - if(data->filename == NULL || strcmp(file, data->filename) != 0) { - fprintf(stderr, "moc: new file, asking for tags\n"); - data->filename = file; - // get tags. - send_int(srv_sock, CMD_GET_FILE_TAGS); - send_str(srv_sock, file); - send_int(srv_sock,TAGS_COMMENTS | TAGS_TIME); - last_cmd = EV_FILE_TAGS; + if(state != STATE_STOP) { + char *file = get_curr_file(srv_sock); + fprintf(stderr, "moc: current file %s\n", file); + // if it's the same file as we had, don't update. + if(data->filename == NULL || strcmp(file, data->filename) != 0) { + fprintf(stderr, "moc: new file, asking for tags\n"); + data->filename = file; + // get tags. + send_int(srv_sock, CMD_GET_FILE_TAGS); + send_str(srv_sock, file); + send_int(srv_sock,TAGS_COMMENTS | TAGS_TIME); + last_cmd = EV_FILE_TAGS; + } + } else { + reset_data(data); } } else { @@ -519,15 +532,10 @@ void *moc_loop2(void *input) { fprintf(stderr, "moc: end of loop\n"); return NULL; } - extern struct moc *moc_init() { struct moc *moc = (struct moc*)malloc(sizeof(struct moc)); - moc->filename = NULL; - moc->title = NULL; - moc->album = NULL; - moc->artist = NULL; - moc->time = -1; + reset_data(moc); pthread_t thread_id; if (pthread_mutex_init(&moc->lock, NULL) != 0) { |