int streamPlaylist(shout_t *shout, const char *fileName) { const char *song; char lastSong[PATH_MAX]; if (playlist == NULL) { if (pezConfig->fileNameIsProgram) { if ((playlist = playlist_program(fileName)) == NULL) return (0); } else { if ((playlist = playlist_read(fileName)) == NULL) return (0); if (vFlag && playlist_get_num_items(playlist) == 0) printf("%s: Warning: Playlist '%s' is empty\n", __progname, fileName); } } else { /* * XXX: This preserves traditional behavior, however, * rereading the playlist after each walkthrough seems a * bit more logical. */ playlist_rewind(playlist); } if (!pezConfig->fileNameIsProgram && pezConfig->shuffle) playlist_shuffle(playlist); while ((song = playlist_get_next(playlist)) != NULL) { strlcpy(lastSong, song, sizeof(lastSong)); if (!streamFile(shout, song)) return (0); if (quit) break; if (rereadPlaylist) { rereadPlaylist = rereadPlaylist_notify = 0; if (pezConfig->fileNameIsProgram) continue; printf("%s: Rereading playlist\n", __progname); if (!playlist_reread(&playlist)) return (0); if (pezConfig->shuffle) playlist_shuffle(playlist); else { playlist_goto_entry(playlist, lastSong); playlist_skip_next(playlist); } continue; } } return (1); }
/* Start playback of a playlist, checking for bookmark autoload, modified * playlists, etc., as required. Returns false if playback wasn't started, * or started via bookmark autoload, true otherwise. * * Pointers to both the full pathname and the separated parts needed to * avoid allocating yet another path buffer on the stack (and save some * code; the caller typically needs to create the full pathname anyway)... */ bool ft_play_playlist(char* pathname, char* dirname, char* filename) { if (global_settings.party_mode && audio_status()) { splash(HZ, ID2P(LANG_PARTY_MODE)); return false; } if (bookmark_autoload(pathname)) { return false; } splash(0, ID2P(LANG_WAIT)); /* about to create a new current playlist... allow user to cancel the operation */ if (!warn_on_pl_erase()) return false; if (playlist_create(dirname, filename) != -1) { if (global_settings.playlist_shuffle) { playlist_shuffle(current_tick, -1); } playlist_start(0, 0); return true; } return false; }
int main(int argc, char *argv[]) { int c; char *configFile = NULL; char *host = NULL; unsigned short port = 0; char *mount = NULL; shout_t *shout; extern char *optarg; extern int optind; #ifdef HAVE_SIGNALS struct sigaction act; unsigned int i; #endif #ifdef XALLOC_DEBUG xalloc_initialize_debug(2, NULL); #else xalloc_initialize(); #endif /* XALLOC_DEBUG */ playlist_init(); shout_init(); __progname = getProgname(argv[0]); pezConfig = getEZConfig(); mFlag = 0; nFlag = 0; qFlag = 0; vFlag = 0; while ((c = local_getopt(argc, argv, "c:hmnqsVv")) != -1) { switch (c) { case 'c': if (configFile != NULL) { printf("Error: multiple -c arguments given\n"); usage(); return (ez_shutdown(2)); } configFile = xstrdup(optarg); break; case 'h': usage(); usageHelp(); return (ez_shutdown(0)); case 'm': mFlag = 1; break; case 'n': nFlag = 1; break; case 'q': qFlag = 1; break; case 's': sFlag = 1; break; case 'V': printf("%s\n", PACKAGE_STRING); return (ez_shutdown(0)); case 'v': vFlag++; break; case '?': usage(); return (ez_shutdown(2)); default: break; } } argc -= optind; argv += optind; if (sFlag) { playlist_t *pl; const char *entry; switch (argc) { case 0: pl = playlist_read(NULL); if (pl == NULL) return (ez_shutdown(1)); break; case 1: pl = playlist_read(argv[0]); if (pl == NULL) return (ez_shutdown(1)); break; default: printf("Error: Too many arguments.\n"); return (ez_shutdown(2)); } playlist_shuffle(pl); while ((entry = playlist_get_next(pl)) != NULL) printf("%s\n", entry); playlist_free(&pl); return (ez_shutdown(0)); } if (configFile == NULL) { printf("You must supply a config file with the -c argument.\n"); usage(); return (ez_shutdown(2)); } else { /* * Attempt to open configFile here for a more meaningful error * message. Where possible, do it with stat() and check for * safe config file permissions. */ #ifdef HAVE_STAT struct stat st; if (stat(configFile, &st) == -1) { printf("%s: %s\n", configFile, strerror(errno)); usage(); return (ez_shutdown(2)); } if (vFlag && (st.st_mode & (S_IRGRP | S_IROTH))) printf("%s: Warning: %s is group and/or world readable\n", __progname, configFile); if (st.st_mode & (S_IWGRP | S_IWOTH)) { printf("%s: Error: %s is group and/or world writeable\n", __progname, configFile); return (ez_shutdown(2)); } #else FILE *tmp; if ((tmp = fopen(configFile, "r")) == NULL) { printf("%s: %s\n", configFile, strerror(errno)); usage(); return (ez_shutdown(2)); } fclose(tmp); #endif /* HAVE_STAT */ } if (!parseConfig(configFile)) return (ez_shutdown(2)); if (pezConfig->URL == NULL) { printf("%s: Error: Missing <url>\n", configFile); return (ez_shutdown(2)); } if (!urlParse(pezConfig->URL, &host, &port, &mount)) { printf("Must be of the form ``http://server:port/mountpoint''\n"); return (ez_shutdown(2)); } if (strlen(host) == 0) { printf("%s: Error: Invalid <url>: Missing server:\n", configFile); printf("Must be of the form ``http://server:port/mountpoint''\n"); return (ez_shutdown(2)); } if (strlen(mount) == 0) { printf("%s: Error: Invalid <url>: Missing mountpoint:\n", configFile); printf("Must be of the form ``http://server:port/mountpoint''\n"); return (ez_shutdown(2)); } if (pezConfig->password == NULL) { printf("%s: Error: Missing <sourcepassword>\n", configFile); return (ez_shutdown(2)); } if (pezConfig->fileName == NULL) { printf("%s: Error: Missing <filename>\n", configFile); return (ez_shutdown(2)); } if (pezConfig->format == NULL) { printf("%s: Warning: Missing <format>:\n", configFile); printf("Specify a stream format of either MP3, VORBIS or THEORA\n"); } xfree(configFile); if ((shout = stream_setup(host, port, mount)) == NULL) return (ez_shutdown(1)); if (pezConfig->metadataProgram != NULL) metadataFromProgram = 1; else metadataFromProgram = 0; #ifdef HAVE_SIGNALS memset(&act, 0, sizeof(act)); act.sa_handler = sig_handler; # ifdef SA_RESTART act.sa_flags = SA_RESTART; # endif for (i = 0; i < sizeof(ezstream_signals) / sizeof(int); i++) { if (sigaction(ezstream_signals[i], &act, NULL) == -1) { printf("%s: sigaction(): %s\n", __progname, strerror(errno)); return (ez_shutdown(1)); } } /* * Ignore SIGPIPE, which has been seen to give a long-running ezstream * process trouble. EOF and/or EPIPE are also easier to handle. */ act.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &act, NULL) == -1) { printf("%s: sigaction(): %s\n", __progname, strerror(errno)); return (ez_shutdown(1)); } #endif /* HAVE_SIGNALS */ if (shout_open(shout) == SHOUTERR_SUCCESS) { int ret; printf("%s: Connected to http://%s:%hu%s\n", __progname, host, port, mount); if (pezConfig->fileNameIsProgram || strrcasecmp(pezConfig->fileName, ".m3u") == 0 || strrcasecmp(pezConfig->fileName, ".txt") == 0) playlistMode = 1; else playlistMode = 0; if (vFlag && pezConfig->fileNameIsProgram) printf("%s: Using program '%s' to get filenames for streaming\n", __progname, pezConfig->fileName); do { if (playlistMode) { ret = streamPlaylist(shout, pezConfig->fileName); } else { ret = streamFile(shout, pezConfig->fileName); } if (quit) break; if (pezConfig->streamOnce) break; } while (ret); shout_close(shout); } else printf("%s: Connection to http://%s:%hu%s failed: %s\n", __progname, host, port, mount, shout_get_error(shout)); if (quit) printf("\r%s: SIGINT or SIGTERM received\n", __progname); if (vFlag) printf("%s: Exiting ...\n", __progname); xfree(host); xfree(mount); playlist_free(&playlist); return (ez_shutdown(0)); }
/* CONTEXT_[TREE|ID3DB] playlist options */ static bool add_to_playlist(int position, bool queue) { bool new_playlist = !(audio_status() & AUDIO_STATUS_PLAY); const char *lines[] = { ID2P(LANG_RECURSE_DIRECTORY_QUESTION), selected_file }; const struct text_message message={lines, 2}; splash(0, ID2P(LANG_WAIT)); if (new_playlist) playlist_create(NULL, NULL); /* always set seed before inserting shuffled */ if (position == PLAYLIST_INSERT_SHUFFLED || position == PLAYLIST_INSERT_LAST_SHUFFLED) { srand(current_tick); if (position == PLAYLIST_INSERT_LAST_SHUFFLED) playlist_set_last_shuffled_start(); } #ifdef HAVE_TAGCACHE if (context == CONTEXT_ID3DB) { tagtree_insert_selection_playlist(position, queue); } else #endif { if ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO) playlist_insert_track(NULL, selected_file, position, queue, true); else if (selected_file_attr & ATTR_DIRECTORY) { bool recurse = false; if (global_settings.recursive_dir_insert != RECURSE_ASK) recurse = (bool)global_settings.recursive_dir_insert; else { /* Ask if user wants to recurse directory */ recurse = (gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES); } playlist_insert_directory(NULL, selected_file, position, queue, recurse); } else if ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U) playlist_insert_playlist(NULL, selected_file, position, queue); } if (new_playlist && (playlist_amount() > 0)) { /* nothing is currently playing so begin playing what we just inserted */ if (global_settings.playlist_shuffle) playlist_shuffle(current_tick, -1); playlist_start(0,0); onplay_result = ONPLAY_START_PLAY; } return false; }
bool bookmark_play(char *resume_file, int index, int offset, int seed, char *filename) { int i; char* suffix = strrchr(resume_file, '.'); bool started = false; if (suffix != NULL && (!strcasecmp(suffix, ".m3u") || !strcasecmp(suffix, ".m3u8"))) { /* Playlist playback */ char* slash; /* check that the file exists */ if(!file_exists(resume_file)) return false; slash = strrchr(resume_file,'/'); if (slash) { char* cp; *slash=0; cp=resume_file; if (!cp[0]) cp="/"; if (playlist_create(cp, slash+1) != -1) { if (global_settings.playlist_shuffle) playlist_shuffle(seed, -1); playlist_start(index,offset); started = true; } *slash='/'; } } else { /* Directory playback */ lastdir[0]='\0'; if (playlist_create(resume_file, NULL) != -1) { char filename_buf[MAX_PATH + 1]; const char* peek_filename; resume_directory(resume_file); if (global_settings.playlist_shuffle) playlist_shuffle(seed, -1); /* Check if the file is at the same spot in the directory, else search for it */ peek_filename = playlist_peek(index, filename_buf, sizeof(filename_buf)); if (peek_filename == NULL) { /* playlist has shrunk, search from the top */ index = 0; peek_filename = playlist_peek(index, filename_buf, sizeof(filename_buf)); if (peek_filename == NULL) return false; } if (strcmp(strrchr(peek_filename, '/') + 1, filename)) { for ( i=0; i < playlist_amount(); i++ ) { peek_filename = playlist_peek(i, filename_buf, sizeof(filename_buf)); if (peek_filename == NULL) return false; if (!strcmp(strrchr(peek_filename, '/') + 1, filename)) break; } if (i < playlist_amount()) index = i; else return false; } playlist_start(index,offset); started = true; } } if (started) start_wps = true; return started; }
void on_shuffle_activate(GtkToggleAction * action, gpointer user_data) { prefs.shuffle = gtk_toggle_action_get_active(action); update_ui_shuffle(app); playlist_shuffle(get_playlist(app)); }
/* Main viewer function. Filename identifies playlist to be viewed. If NULL, view current playlist. */ enum playlist_viewer_result playlist_viewer_ex(const char* filename) { enum playlist_viewer_result ret = PLAYLIST_VIEWER_OK; bool exit = false; /* exit viewer */ int button; bool dirty = false; struct gui_synclist playlist_lists; if (!playlist_viewer_init(&viewer, filename, false)) goto exit; push_current_activity(ACTIVITY_PLAYLISTVIEWER); gui_synclist_init(&playlist_lists, playlist_callback_name, &viewer, false, 1, NULL); gui_synclist_set_voice_callback(&playlist_lists, playlist_callback_voice); gui_synclist_set_icon_callback(&playlist_lists, global_settings.playlist_viewer_icons? &playlist_callback_icons:NULL); gui_synclist_set_nb_items(&playlist_lists, viewer.num_tracks); gui_synclist_set_title(&playlist_lists, str(LANG_PLAYLIST), Icon_Playlist); gui_synclist_select_item(&playlist_lists, viewer.selected_track); gui_synclist_draw(&playlist_lists); gui_synclist_speak_item(&playlist_lists); while (!exit) { int track; if (global_status.resume_index != -1 && !viewer.playlist) playlist_get_resume_info(&track); else track = -1; if (track != viewer.current_playing_track || playlist_amount_ex(viewer.playlist) != viewer.num_tracks) { /* Playlist has changed (new track started?) */ if (!update_playlist(false)) goto exit; /*Needed because update_playlist gives wrong value when playing is stopped*/ viewer.current_playing_track = track; gui_synclist_set_nb_items(&playlist_lists, viewer.num_tracks); gui_synclist_draw(&playlist_lists); } /* Timeout so we can determine if play status has changed */ bool res = list_do_action(CONTEXT_TREE, HZ/2, &playlist_lists, &button, LIST_WRAP_UNLESS_HELD); /* during moving, another redraw is going to be needed, * since viewer.selected_track is updated too late (after the first draw) * drawing the moving item needs it */ viewer.selected_track=gui_synclist_get_sel_pos(&playlist_lists); if (res) { bool reload = playlist_buffer_needs_reload(&viewer.buffer, viewer.selected_track); if (reload) playlist_buffer_load_entries_screen(&viewer.buffer, button == ACTION_STD_NEXT ? FORWARD : BACKWARD); if (reload || viewer.moving_track >= 0) gui_synclist_draw(&playlist_lists); } switch (button) { case ACTION_TREE_WPS: case ACTION_STD_CANCEL: { if (viewer.moving_track >= 0) { viewer.selected_track = viewer.moving_track; gui_synclist_select_item(&playlist_lists, viewer.moving_track); viewer.moving_track = -1; viewer.moving_playlist_index = -1; gui_synclist_draw(&playlist_lists); } else { exit = true; ret = PLAYLIST_VIEWER_CANCEL; } break; } case ACTION_STD_OK: { struct playlist_entry * current_track = playlist_buffer_get_track(&viewer.buffer, viewer.selected_track); if (viewer.moving_track >= 0) { /* Move track */ int ret_val; ret_val = playlist_move(viewer.playlist, viewer.moving_playlist_index, current_track->index); if (ret_val < 0) splashf(HZ, (unsigned char *)"%s %s", str(LANG_MOVE), str(LANG_FAILED)); update_playlist(true); viewer.moving_track = -1; viewer.moving_playlist_index = -1; dirty = true; } else if (!viewer.playlist) { /* play new track */ if (!global_settings.party_mode) { playlist_start(current_track->index, 0); update_playlist(false); } } else if (!global_settings.party_mode) { int start_index = current_track->index; if (!warn_on_pl_erase()) { gui_synclist_draw(&playlist_lists); break; } /* New playlist */ if (playlist_set_current(viewer.playlist) < 0) goto exit; if (global_settings.playlist_shuffle) start_index = playlist_shuffle(current_tick, start_index); playlist_start(start_index, 0); /* Our playlist is now the current list */ if (!playlist_viewer_init(&viewer, NULL, true)) goto exit; exit = true; } gui_synclist_draw(&playlist_lists); break; } case ACTION_STD_CONTEXT: { /* ON+PLAY menu */ int ret_val; ret_val = onplay_menu(viewer.selected_track); if (ret_val < 0) { ret = PLAYLIST_VIEWER_USB; goto exit; } else if (ret_val > 0) { /* Playlist changed */ gui_synclist_del_item(&playlist_lists); update_playlist(true); if (viewer.num_tracks <= 0) exit = true; if (viewer.selected_track >= viewer.num_tracks) viewer.selected_track = viewer.num_tracks-1; dirty = true; } gui_synclist_draw(&playlist_lists); break; } case ACTION_STD_MENU: ret = PLAYLIST_VIEWER_MAINMENU; goto exit; default: if(default_event_handler(button) == SYS_USB_CONNECTED) { ret = PLAYLIST_VIEWER_USB; goto exit; } break; } } exit: pop_current_activity(); if (viewer.playlist) { if(dirty && yesno_pop(ID2P(LANG_SAVE_CHANGES))) save_playlist_screen(viewer.playlist); playlist_close(viewer.playlist); } return ret; }
int ft_enter(struct tree_context* c) { int rc = GO_TO_PREVIOUS; char buf[MAX_PATH]; struct entry* file = tree_get_entry_at(c, c->selected_item); int file_attr = file->attr; if (c->currdir[1]) snprintf(buf,sizeof(buf),"%s/%s",c->currdir, file->name); else snprintf(buf,sizeof(buf),"/%s",file->name); if (file_attr & ATTR_DIRECTORY) { memcpy(c->currdir, buf, sizeof(c->currdir)); if ( c->dirlevel < MAX_DIR_LEVELS ) c->selected_item_history[c->dirlevel] = c->selected_item; c->dirlevel++; c->selected_item=0; } else { int seed = current_tick; bool play = false; int start_index=0; switch ( file_attr & FILE_ATTR_MASK ) { case FILE_ATTR_M3U: if (!bookmark_autoload(buf)) playlist_viewer_ex(buf); break; case FILE_ATTR_AUDIO: if (bookmark_autoload(c->currdir)) break; splash(0, ID2P(LANG_WAIT)); /* about to create a new current playlist... allow user to cancel the operation */ if (!warn_on_pl_erase()) break; if (global_settings.party_mode && audio_status()) { playlist_insert_track(NULL, buf, PLAYLIST_INSERT_LAST, true, true); splash(HZ, ID2P(LANG_QUEUE_LAST)); } else if (playlist_create(c->currdir, NULL) != -1) { start_index = ft_build_playlist(c, c->selected_item); if (global_settings.playlist_shuffle) { start_index = playlist_shuffle(seed, start_index); /* when shuffling dir.: play all files even if the file selected by user is not the first one */ if (!global_settings.play_selected) start_index = 0; } playlist_start(start_index, 0); play = true; } break; #if CONFIG_TUNER /* fmr preset file */ case FILE_ATTR_FMR: splash(0, ID2P(LANG_WAIT)); /* Preset inside the default folder. */ if(!strncasecmp(FMPRESET_PATH, buf, strlen(FMPRESET_PATH))) { set_file(buf, global_settings.fmr_file, MAX_FILENAME); radio_load_presets(global_settings.fmr_file); } /* * Preset outside default folder, we can choose such only * if we are out of the radio screen, so the check for the * radio status isn't neccessary */ else { radio_load_presets(buf); } rc = GO_TO_FM; break; case FILE_ATTR_FMS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.fms_file, MAX_FILENAME); settings_apply_skins(); break; #ifdef HAVE_REMOTE_LCD case FILE_ATTR_RFMS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.rfms_file, MAX_FILENAME); settings_apply_skins(); break; #endif #endif #ifdef HAVE_LCD_BITMAP case FILE_ATTR_SBS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.sbs_file, MAX_FILENAME); settings_apply_skins(); break; #endif #ifdef HAVE_REMOTE_LCD case FILE_ATTR_RSBS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.rsbs_file, MAX_FILENAME); settings_apply_skins(); break; #endif /* wps config file */ case FILE_ATTR_WPS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.wps_file, MAX_FILENAME); settings_apply_skins(); break; #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) /* remote-wps config file */ case FILE_ATTR_RWPS: splash(0, ID2P(LANG_WAIT)); set_file(buf, (char *)global_settings.rwps_file, MAX_FILENAME); settings_apply_skins(); break; #endif case FILE_ATTR_CFG: splash(0, ID2P(LANG_WAIT)); if (!settings_load_config(buf,true)) break; splash(HZ, ID2P(LANG_SETTINGS_LOADED)); break; case FILE_ATTR_BMARK: splash(0, ID2P(LANG_WAIT)); bookmark_load(buf, false); rc = GO_TO_FILEBROWSER; break; case FILE_ATTR_LNG: splash(0, ID2P(LANG_WAIT)); if (lang_core_load(buf)) { splash(HZ, ID2P(LANG_FAILED)); break; } set_file(buf, (char *)global_settings.lang_file, MAX_FILENAME); talk_init(); /* use voice of same language */ viewportmanager_theme_changed(THEME_LANGUAGE); settings_apply_skins(); splash(HZ, ID2P(LANG_LANGUAGE_LOADED)); break; #ifdef HAVE_LCD_BITMAP case FILE_ATTR_FONT: ft_load_font(buf); break; case FILE_ATTR_KBD: splash(0, ID2P(LANG_WAIT)); if (!load_kbd(buf)) splash(HZ, ID2P(LANG_KEYBOARD_LOADED)); set_file(buf, (char *)global_settings.kbd_file, MAX_FILENAME); break; #endif #if (CONFIG_PLATFORM & PLATFORM_NATIVE) /* firmware file */ case FILE_ATTR_MOD: splash(0, ID2P(LANG_WAIT)); audio_hard_stop(); rolo_load(buf); break; #endif /* plugin file */ case FILE_ATTR_ROCK: case FILE_ATTR_LUA: { char *plugin = buf, *argument = NULL, lua_path[MAX_PATH]; int ret; if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_LUA) { snprintf(lua_path, sizeof(lua_path)-1, "%s/lua.rock", VIEWERS_DIR); /* Use a #define here ? */ plugin = lua_path; argument = buf; } if (global_settings.party_mode && audio_status()) { splash(HZ, ID2P(LANG_PARTY_MODE)); break; } ret = plugin_load(plugin, argument); switch (ret) { case PLUGIN_GOTO_WPS: play = true; break; case PLUGIN_USB_CONNECTED: if(*c->dirfilter > NUM_FILTER_MODES) /* leave sub-browsers after usb, doing otherwise might be confusing to the user */ rc = GO_TO_ROOT; else rc = GO_TO_FILEBROWSER; break; /* case PLUGIN_ERROR: case PLUGIN_OK: */ default: break; } break; } case FILE_ATTR_CUE: display_cuesheet_content(buf); break; default: { const char* plugin; if (global_settings.party_mode && audio_status()) { splash(HZ, ID2P(LANG_PARTY_MODE)); break; } struct entry* file = tree_get_entry_at(c, c->selected_item); plugin = filetype_get_plugin(file); if (plugin) { switch (plugin_load(plugin,buf)) { case PLUGIN_USB_CONNECTED: rc = GO_TO_FILEBROWSER; break; case PLUGIN_GOTO_WPS: rc = GO_TO_WPS; break; /* case PLUGIN_OK: case PLUGIN_ERROR: */ default: break; } } break; } } if ( play ) { /* the resume_index must always be the index in the shuffled list in case shuffle is enabled */ global_status.resume_index = start_index; global_status.resume_offset = 0; status_save(); rc = GO_TO_WPS; } else { if (*c->dirfilter > NUM_FILTER_MODES && *c->dirfilter != SHOW_CFG && *c->dirfilter != SHOW_FONT && *c->dirfilter != SHOW_PLUGINS) { rc = GO_TO_ROOT; } } } return rc; }