static int open_file(struct demuxer *demuxer, enum demux_check check) { bool force = check < DEMUX_CHECK_UNSAFE || check == DEMUX_CHECK_REQUEST; struct pl_parser *p = talloc_zero(NULL, struct pl_parser); p->pl = talloc_zero(p, struct playlist); bstr probe_buf = stream_peek(demuxer->stream, PROBE_SIZE); p->s = open_memory_stream(probe_buf.start, probe_buf.len); p->utf16 = stream_skip_bom(p->s); p->probing = true; const struct pl_format *fmt = probe_pl(p, force); free_stream(p->s); playlist_clear(p->pl); if (!fmt) { talloc_free(p); return -1; } p->probing = false; p->s = demuxer->stream; p->utf16 = stream_skip_bom(p->s); bool ok = fmt->parse(p) >= 0; if (ok) playlist_add_base_path(p->pl, mp_dirname(demuxer->filename)); demuxer->playlist = talloc_steal(demuxer, p->pl); demuxer->filetype = fmt->name; talloc_free(p); return ok ? 0 : -1; }
void fb_shuffle(int shuffle) { char **item, *tmp; int i, j, k, n; if (shuffle) mvpw_set_menu_title(playlist_widget, "Shuffle Play"); else mvpw_set_menu_title(playlist_widget, "Play All"); item = alloca(sizeof(char*) * MAX_PLAYLIST_ENTRIES); // Recurse from the current directory and find all // audio files n = 0; recurse_find_audio(cwd, item, &n); if (n == 0) { gui_error("No audio files exist in this directory or its subdirectories"); return; } if (shuffle && (n > 1)) { for (i=0; i < MAX_PLAYLIST_ENTRIES; i++) { j = rand() % n; k = rand() % n; tmp = item[k]; item[k] = item[j]; item[j] = tmp; } } printf("created playlist of %d songs\n", n); switch_hw_state(MVPMC_STATE_FILEBROWSER); video_functions = &file_functions; playlist_clear(); mvpw_show(playlist_widget); mvpw_focus(playlist_widget); playlist_create(item, n); // Release the list of items for (i = 0; i < n; i++) free(item[i]); if (shuffle) mvpw_set_text_str(fb_name, "Shuffle Play"); else mvpw_set_text_str(fb_name, "Play All"); mvpw_show(fb_progress); mvpw_set_timer(fb_progress, fb_osd_update, 500); playlist_play(NULL); }
void fb_exit(void) { audio_stop = 1; audio_clear(); pthread_kill(audio_thread, SIGURG); if (current) { free(current); current = NULL; } mvpw_hide(fb_progress); video_clear(); av_stop(); if (!mvpw_visible(playlist_widget)) playlist_clear(); }
void merge_playlist_files(struct playlist *pl) { if (!pl->first) return; char *edl = talloc_strdup(NULL, "edl://"); for (struct playlist_entry *e = pl->first; e; e = e->next) { if (e != pl->first) edl = talloc_strdup_append_buffer(edl, ";"); // Escape if needed if (e->filename[strcspn(e->filename, "=%,;\n")] || bstr_strip(bstr0(e->filename)).len != strlen(e->filename)) { // %length% edl = talloc_asprintf_append_buffer(edl, "%%%zd%%", strlen(e->filename)); } edl = talloc_strdup_append_buffer(edl, e->filename); } playlist_clear(pl); playlist_add_file(pl, edl); talloc_free(edl); }
/* callback for control buttons */ static void control_cb(AppData *appdata, int command) { switch (command) { case (PLAY): if (decoder_is_playing(appdata->decoder)) { decoder_stop(appdata->decoder); gui_set_paused(appdata->gui, TRUE); } else { decoder_play(appdata->decoder); gui_set_paused(appdata->gui, FALSE); } break; case (STOP): decoder_stop(appdata->decoder); decoder_seek(appdata->decoder, 0); appdata->current_position = decoder_get_position(appdata->decoder); gui_set_time(appdata->gui, 0, decoder_get_total(appdata->decoder)); gui_set_paused(appdata->gui, FALSE); break; case (PREVIOUS): playlist_previous(appdata->playlist); break; case (NEXT): decoder_stop(appdata->decoder); playlist_next(appdata->playlist); break; case (CLEAR): playlist_clear(appdata->playlist); default: break; } }
void playlist_manager::activeplaylist_clear() { t_size playlist = get_active_playlist(); if (playlist != pfc_infinite) playlist_clear(playlist); }
static void fifo_execute (const char *command) { if (!g_ascii_strncasecmp (command, "quit", 4)) main_quit (); else if (!g_ascii_strncasecmp (command, "play", 4)) music_play (); else if (!g_ascii_strncasecmp (command, "pause", 5)) if (music_playing) music_pause (); else music_play (); else if (!g_ascii_strncasecmp (command, "stop", 4)) music_stop (); else if (!g_ascii_strncasecmp (command, "next", 4)) { playlist_advance (1, TRUE); } else if (!g_ascii_strncasecmp (command, "prev", 4)) { playlist_advance (-1, TRUE); } else if (!g_ascii_strncasecmp (command, "append", 6)) { if (strlen (command) > 7) { gchar *u; const gchar *path; path = (command + 7); if (!(u = g_filename_to_utf8 (path, -1, NULL, NULL, NULL))) { g_warning (_("Skipping '%s'. Could not convert to UTF-8. " "See the README for a possible solution."), path); } else { playlist_append_single (u); g_free (u); } } } else if (!g_ascii_strncasecmp (command, "track", 5)) { if (strlen (command) > 6) { int i = atoi (command + 6); playlist_seek (i - 1); /* first track is '1' */ } } else if (!g_ascii_strncasecmp (command, "remove", 6)) { if (strlen (command) > 7) { int i = atoi (command + 7); playlist_remove (i - 1); /* first track is '1' */ } } else if (!g_ascii_strncasecmp (command, "clear", 5)) { playlist_clear (); } else if (!g_ascii_strncasecmp (command, "move", 4)) { if (strlen (command) > 5) { char *p; int i = strtol (command + 5, &p, 10); if (strlen (command) > (unsigned)(p - command)) { int before = atoi (p); playlist_move (i - 1, before - 1); /* first track is '1' */ } } } else if (!g_ascii_strncasecmp (command, "loop", 4)) { main_set_loop_at_end(!main_loop_at_end); } else if (!g_ascii_strncasecmp (command, "random", 6)) { main_set_random_order(!main_random_order); } else if (!g_ascii_strncasecmp (command, "dump", 4)) { playlist_dump (); } else if (!g_ascii_strncasecmp (command, "connect", 7)) { if (strlen (command) > 8) { fifo_add_notify (command + 8); } } }
void update_vo_playback_state(struct MPContext *mpctx) { if (mpctx->video_out && mpctx->video_out->config_ok) { struct voctrl_playback_state oldstate = mpctx->vo_playback_state; struct voctrl_playback_state newstate = { .taskbar_progress = mpctx->opts->vo->taskbar_progress, .playing = mpctx->playing, .paused = mpctx->paused, .percent_pos = get_percent_pos(mpctx), }; if (oldstate.taskbar_progress != newstate.taskbar_progress || oldstate.playing != newstate.playing || oldstate.paused != newstate.paused || oldstate.percent_pos != newstate.percent_pos) { // Don't update progress bar if it was and still is hidden if ((oldstate.playing && oldstate.taskbar_progress) || (newstate.playing && newstate.taskbar_progress)) { vo_control_async(mpctx->video_out, VOCTRL_UPDATE_PLAYBACK_STATE, &newstate); } mpctx->vo_playback_state = newstate; } } else { mpctx->vo_playback_state = (struct voctrl_playback_state){ 0 }; } } void update_window_title(struct MPContext *mpctx, bool force) { if (!mpctx->video_out && !mpctx->ao) { talloc_free(mpctx->last_window_title); mpctx->last_window_title = NULL; return; } char *title = mp_property_expand_string(mpctx, mpctx->opts->wintitle); if (!mpctx->last_window_title || force || strcmp(title, mpctx->last_window_title) != 0) { talloc_free(mpctx->last_window_title); mpctx->last_window_title = talloc_steal(mpctx, title); if (mpctx->video_out) vo_control(mpctx->video_out, VOCTRL_UPDATE_WINDOW_TITLE, title); if (mpctx->ao) { ao_control(mpctx->ao, AOCONTROL_UPDATE_STREAM_TITLE, title); } } else { talloc_free(title); } } void error_on_track(struct MPContext *mpctx, struct track *track) { if (!track || !track->selected) return; mp_deselect_track(mpctx, track); if (track->type == STREAM_AUDIO) MP_INFO(mpctx, "Audio: no audio\n"); if (track->type == STREAM_VIDEO) MP_INFO(mpctx, "Video: no video\n"); if (mpctx->opts->stop_playback_on_init_failure || !(mpctx->vo_chain || mpctx->ao_chain)) { if (!mpctx->stop_play) mpctx->stop_play = PT_ERROR; if (mpctx->error_playing >= 0) mpctx->error_playing = MPV_ERROR_NOTHING_TO_PLAY; } mp_wakeup_core(mpctx); } int stream_dump(struct MPContext *mpctx, const char *source_filename) { struct MPOpts *opts = mpctx->opts; stream_t *stream = stream_open(source_filename, mpctx->global); if (!stream) return -1; int64_t size = stream_get_size(stream); FILE *dest = fopen(opts->stream_dump, "wb"); if (!dest) { MP_ERR(mpctx, "Error opening dump file: %s\n", mp_strerror(errno)); return -1; } bool ok = true; while (mpctx->stop_play == KEEP_PLAYING && ok) { if (!opts->quiet && ((stream->pos / (1024 * 1024)) % 2) == 1) { uint64_t pos = stream->pos; MP_MSG(mpctx, MSGL_STATUS, "Dumping %lld/%lld...", (long long int)pos, (long long int)size); } bstr data = stream_peek(stream, STREAM_MAX_BUFFER_SIZE); if (data.len == 0) { ok &= stream->eof; break; } ok &= fwrite(data.start, data.len, 1, dest) == 1; stream_skip(stream, data.len); mp_wakeup_core(mpctx); // don't actually sleep mp_idle(mpctx); // but process input } ok &= fclose(dest) == 0; free_stream(stream); return ok ? 0 : -1; } void merge_playlist_files(struct playlist *pl) { if (!pl->first) return; char *edl = talloc_strdup(NULL, "edl://"); for (struct playlist_entry *e = pl->first; e; e = e->next) { if (e != pl->first) edl = talloc_strdup_append_buffer(edl, ";"); // Escape if needed if (e->filename[strcspn(e->filename, "=%,;\n")] || bstr_strip(bstr0(e->filename)).len != strlen(e->filename)) { // %length% edl = talloc_asprintf_append_buffer(edl, "%%%zd%%", strlen(e->filename)); } edl = talloc_strdup_append_buffer(edl, e->filename); } playlist_clear(pl); playlist_add_file(pl, edl); talloc_free(edl); }
static void select_callback(mvp_widget_t *widget, char *item, void *key) { char path[1024], *ptr; struct stat64 sb; sprintf(path, "%s/%s", cwd, item); if (stat64(path, &sb)!=0) { printf("Could not stat %s error %d\n",item,errno); if (strcmp(item,"../")==0 ) { // probably lost network put you back in root strcpy(cwd,"/"); strcpy(path,"/"); stat64(path, &sb); } } if (current_pl && !is_playlist(item)) { free(current_pl); current_pl = NULL; } if (current_pl && (playlist == NULL)) { free(current_pl); current_pl = NULL; } printf("%s(): path '%s'\n", __FUNCTION__, path); if (current && (strcmp(path, current) == 0)) { printf("selected current item\n"); if (is_video(item) || (is_streaming(item) > 100)) { mvpw_hide(widget); mvpw_hide(fb_progress); av_move(0, 0, 0); screensaver_disable(); return; } } if (current_pl && (strcmp(path, current_pl) == 0)) { if (is_playlist(item)) { mvpw_show(fb_progress); mvpw_set_timer(fb_progress, fb_osd_update, 500); mvpw_hide(widget); printf("Show playlist menu\n"); mvpw_show(playlist_widget); mvpw_focus(playlist_widget); return; } } if (S_ISDIR(sb.st_mode)) { if (strcmp(item, "../") == 0) { strcpy(path, cwd); if (path[strlen(path)-1] == '/') path[strlen(path)-1] = '\0'; if ((ptr=strrchr(path, '/')) != NULL) *ptr = '\0'; if (path[0] == '\0') sprintf(path, "/"); } else { if ((ptr=strrchr(path, '/')) != NULL) *ptr = '\0'; } if (strstr(path,"/uPnP")!=NULL && strstr(cwd,"/uPnP")==NULL ){ mount_djmount(path); } else if (strstr(path,"/uPnP")==NULL && strstr(cwd,"/uPnP")!=NULL ) { unmount_djmount(); } strncpy(cwd, path, sizeof(cwd)); while ((cwd[0] == '/') && (cwd[1] == '/')) memmove(cwd, cwd+1, strlen(cwd)); mvpw_clear_menu(widget); mvpw_set_menu_title(widget, cwd); busy_start(); add_dirs(widget); add_files(widget); busy_end(); mvpw_expose(widget); } else { switch_hw_state(MVPMC_STATE_FILEBROWSER); if (current) free(current); current = NULL; audio_stop = 1; pthread_kill(audio_thread, SIGURG); while (audio_playing) usleep(1000); current = strdup(path); if (is_streaming(item) > 100) { // Use VLC callbacks for streaming items video_functions = &vlc_functions; // Allow broadcast messages to be sent so // we can tell VLC to start the stream vlc_broadcast_enabled = 1; } else { video_functions = &file_functions; } add_osd_widget(fb_program_widget, OSD_PROGRAM, osd_settings.program, NULL); mvpw_set_text_str(fb_name, item); /* * This code sends the currently playing file name to the display. */ snprintf(display_message, sizeof(display_message), "File:%s\n", item); display_send(display_message); audio_clear(); video_clear(); playlist_clear(); if (is_video(item)) { if (key != NULL) { mvpw_hide(widget); mvpw_hide(fb_progress); av_move(0, 0, 0); } else { mvpw_show(fb_progress); } mvpw_set_timer(fb_progress, fb_osd_update, 500); video_play(NULL); mvpw_show(root); mvpw_expose(root); mvpw_focus(root); } else if (is_audio(item) || is_streaming(item)>=0 ) { mvpw_show(fb_progress); mvpw_set_timer(fb_progress, fb_osd_update, 500); audio_play(NULL); } else if (is_image(item)) { mvpw_hide(widget); printf("Displaying image '%s'\n", path); if (mvpw_load_image_jpeg(iw, path) == 0) { mvpw_show_image_jpeg(iw); av_wss_update_aspect(WSS_ASPECT_UNKNOWN); } else { mvpw_set_image(iw, path); } mvpw_show(iw); mvpw_focus(iw); loaded_offset = 0; loaded_status = 0; fb_next_image(1); } else if (is_playlist(item)) { if (current_pl) free(current_pl); current_pl = strdup(path); mvpw_show(fb_progress); mvpw_set_timer(fb_progress, fb_osd_update, 500); mvpw_hide(widget); printf("Show playlist menu\n"); mvpw_show(playlist_widget); mvpw_focus(playlist_widget); playlist_clear(); playlist_play(NULL); } } }