📄 onplay.c
字号:
/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id: onplay.c,v 1.23 2004/03/11 10:43:53 linusnielsen Exp $ * * Copyright (C) 2002 Bj鰎n Stenberg * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/#include <stdio.h>#include <string.h>#include <stdlib.h>#include <stdbool.h>#include "debug.h"#include "sprintf.h"#include "lcd.h"#include "dir.h"#include "file.h"#include "mpeg.h"#include "menu.h"#include "lang.h"#include "playlist.h"#include "button.h"#include "kernel.h"#include "keyboard.h"#include "mp3data.h"#include "id3.h"#include "screens.h"#include "tree.h"#include "buffer.h"#include "settings.h"#include "status.h"#include "playlist_viewer.h"#include "onplay.h"static char* selected_file = NULL;static int selected_file_attr = 0;static int onplay_result = ONPLAY_OK;/* For playlist options */struct playlist_args { int position; bool queue;};static bool add_to_playlist(int position, bool queue){ bool new_playlist = !(mpeg_status() & MPEG_STATUS_PLAY); if (new_playlist) playlist_create(NULL, NULL); if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_MPA) playlist_insert_track(NULL, selected_file, position, queue); 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 */ bool exit = false; lcd_clear_display(); lcd_puts_scroll(0,0,str(LANG_RECURSE_DIRECTORY_QUESTION)); lcd_puts_scroll(0,1,selected_file); #ifdef HAVE_LCD_BITMAP lcd_puts(0,3,str(LANG_CONFIRM_WITH_PLAY_RECORDER)); lcd_puts(0,4,str(LANG_CANCEL_WITH_ANY_RECORDER)); #endif lcd_update(); while (!exit) { int btn = button_get(true); switch (btn) { case BUTTON_PLAY: recurse = true; exit = true; break; default: /* ignore button releases */ if (!(btn & BUTTON_REL)) exit = true; break; } } } playlist_insert_directory(NULL, selected_file, position, queue, recurse); } else if ((selected_file_attr & TREE_ATTR_MASK) == TREE_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); status_set_playmode(STATUS_PLAY); status_draw(false); onplay_result = ONPLAY_START_PLAY; } return false;}static bool view_playlist(void){ bool was_playing = mpeg_status() & MPEG_STATUS_PLAY; bool result; result = playlist_viewer_ex(selected_file); if (!was_playing && (mpeg_status() & MPEG_STATUS_PLAY) && onplay_result == ONPLAY_OK) /* playlist was started from viewer */ onplay_result = ONPLAY_START_PLAY; return result;}/* Sub-menu for playlist options */static bool playlist_options(void){ struct menu_items menu[7]; struct playlist_args args[7]; /* increase these 2 if you add entries! */ int m, i=0, pstart=0, result; bool ret = false; if ((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_M3U) { menu[i].desc = str(LANG_VIEW); menu[i].function = view_playlist; i++; pstart++; } if (mpeg_status() & MPEG_STATUS_PLAY) { menu[i].desc = str(LANG_INSERT); args[i].position = PLAYLIST_INSERT; args[i].queue = false; i++; menu[i].desc = str(LANG_INSERT_FIRST); args[i].position = PLAYLIST_INSERT_FIRST; args[i].queue = false; i++; menu[i].desc = str(LANG_INSERT_LAST); args[i].position = PLAYLIST_INSERT_LAST; args[i].queue = false; i++; menu[i].desc = str(LANG_QUEUE); args[i].position = PLAYLIST_INSERT; args[i].queue = true; i++; menu[i].desc = str(LANG_QUEUE_FIRST); args[i].position = PLAYLIST_INSERT_FIRST; args[i].queue = true; i++; menu[i].desc = str(LANG_QUEUE_LAST); args[i].position = PLAYLIST_INSERT_LAST; args[i].queue = true; i++; } else if (((selected_file_attr & TREE_ATTR_MASK) == TREE_ATTR_MPA) || (selected_file_attr & ATTR_DIRECTORY)) { menu[i].desc = str(LANG_INSERT); args[i].position = PLAYLIST_INSERT; args[i].queue = false; i++; } m = menu_init( menu, i ); result = menu_show(m); if (result >= 0 && result < pstart) ret = menu[result].function(); else if (result >= pstart) ret = add_to_playlist(args[result].position, args[result].queue); menu_exit(m); return ret;}static bool delete_file(void){ bool exit = false; lcd_clear_display(); lcd_puts(0,0,str(LANG_REALLY_DELETE)); lcd_puts_scroll(0,1,selected_file);#ifdef HAVE_LCD_BITMAP lcd_puts(0,3,str(LANG_CONFIRM_WITH_PLAY_RECORDER)); lcd_puts(0,4,str(LANG_CANCEL_WITH_ANY_RECORDER)); #endif lcd_update(); while (!exit) { int btn = button_get(true); switch (btn) { case BUTTON_PLAY: if (!remove(selected_file)) { onplay_result = ONPLAY_RELOAD_DIR; lcd_clear_display(); lcd_puts(0,0,str(LANG_DELETED)); lcd_puts_scroll(0,1,selected_file); lcd_update(); sleep(HZ); exit = true; } break; default: /* ignore button releases */ if (!(btn & BUTTON_REL)) exit = true; break; } } return false;}static bool rename_file(void){ char newname[MAX_PATH]; char* ptr = strrchr(selected_file, '/') + 1; int pathlen = (ptr - selected_file); strncpy(newname, selected_file, sizeof newname); if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) { if (!strlen(selected_file+pathlen) || (rename(selected_file, newname) < 0)) { lcd_clear_display(); lcd_puts(0,0,str(LANG_RENAME)); lcd_puts(0,1,str(LANG_FAILED)); lcd_update(); sleep(HZ*2); } else onplay_result = ONPLAY_RELOAD_DIR; } return false;}static void xingupdate(int percent){ char buf[32]; snprintf(buf, 32, "%d%%", percent); lcd_puts(0, 1, buf); lcd_update();}static int insert_data_in_file(char *fname, int fpos, char *buf, int num_bytes){ int readlen; int rc; int orig_fd, fd; char tmpname[MAX_PATH]; snprintf(tmpname, MAX_PATH, "%s.tmp", fname); orig_fd = open(fname, O_RDONLY); if(orig_fd < 0) { return 10*orig_fd - 1; } fd = creat(tmpname, O_WRONLY); if(fd < 0) { close(orig_fd); return 10*fd - 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -