void ArticleView::on_sound_button_clicked(GtkWidget *object, gpointer user_data) { ResData *pResData = (ResData*)user_data; if(const char *filename = pResData->get_url()) play_sound_file(filename); else g_warning("Unable to load resource: %s", pResData->get_key().c_str()); }
void *sound_thread(void *para) { struct play_para *p = (struct play_para *)para; struct timespec at; int ret = 0; while(!p->terminal) { clock_gettime(CLOCK_REALTIME, &at); at.tv_sec += 5; if ((errno = pthread_cond_timedwait(&p->start_play_cond, &p->start_play_mutex, &at)) == 0) { if (NULL == p->file) continue; ret = play_sound_file(p); if (ret != 0) goto end; if (p->wflag) { pthread_mutex_lock(&p->end_play_mutex); pthread_cond_signal(&p->end_play_cond); pthread_mutex_unlock(&p->end_play_mutex); } } else { if (ETIMEDOUT != errno) { DBG_ERR("Wait start_play_cond fail!\n"); usleep(100 * 1000); } } } end: DBG("Sound thread exit, handle: %d\n", (int)para); pthread_mutex_unlock(&p->start_play_mutex); free(p); pthread_exit((void *)ret); }