// ---------------------------------------------------------------------------
int main(int argc, char* argv[]) {
	// initialize signal handlers
	signal(SIGINT, (sig_t)cleanup);
	signal(SIGHUP, (sig_t)next_song);

	// load settings
	Settings_Load("play.conf");
	
	// start playing
	if(is_mp3(argv[1])) {
		start_player(Settings_Get("program", "player"), argv[1]);
	} else if(is_playlist(argv[1])) {
		// get path
		int i;
		for(i = strlen(argv[1]) - 1; i >= 0; i--) {
		  if(argv[1][i] == '/') {
		    strcpy(root_path, argv[1]);
		    root_path[i] = '\0';
		    break;
		  }
		}
		//printf("playlist\r\n");
		play_playlist(Settings_Get("program", "player"), argv[1]);
	}
	
	// done playing, reset id3 info
	FILE* f = fopen(Settings_Get("path", "current_song"), "w");
	fprintf(f, "(no artist) - (no title)\r\n");
	fclose(f);
	
	Settings_Unload();
	
	return 0;
}
Beispiel #2
0
static int play_file(const char *filename, struct params *par) {
    size_t len = strlen(filename);

#define ENDS_IN(EXT) !strcasecmp(EXT, filename + len - sizeof(EXT) + 1)

    if (ENDS_IN(".m3u") || ENDS_IN(".m3u8"))
        return play_playlist(filename, par);
    else if (ENDS_IN(".bz2"))
        return play_compressed_file(filename, par, "bzip2 -cd");
    else if (ENDS_IN(".gz"))
        return play_compressed_file(filename, par, "gzip -cd");
    else if (ENDS_IN(".lzma"))
        return play_compressed_file(filename, par, "lzma -cd");
    else if (ENDS_IN(".xz"))
        return play_compressed_file(filename, par, "xz -cd");
    else
        return play_vgmstream(filename, par);
}
Beispiel #3
0
int main(int argc, char **argv) {
    int status = 0;
    struct params par;
    int opt;

    signal(SIGHUP,  interrupt_handler);
    signal(SIGINT,  interrupt_handler);
    signal(SIGQUIT, interrupt_handler);

    ao_initialize();
    driver_id = ao_default_driver_id();
    memset(&current_sample_format, 0, sizeof(current_sample_format));

    if (argc == 1) {
        /* We were invoked with no arguments */
        usage(argv[0]);
        goto done;
    }

    again:

    {
        struct params default_par = DEFAULT_PARAMS;
        memcpy(&par, &default_par, sizeof(par));
    }

    while ((opt = getopt(argc, argv, "-D:F:L:M:S:b:d:f:o:@:hrv")) != -1) {
        switch (opt) {
            case '@':
                if (play_playlist(optarg, &par)) {
                    status = 1;
                    goto done;
                }
                break;
            case 'D':
                par.fade_delay = atof(optarg);
                break;
            case 'F':
                par.fade_time = atof(optarg);
                break;
            case 'L':
                par.loop_count = atoi(optarg);
                break;
            case 'M':
                par.min_time = atof(optarg);
                par.loop_count = -1;
                break;
            case 'S':
                par.stream_index = atoi(optarg);
                break;
            case 'b':
                if (!buffer)
                    buffer_size_kb = atoi(optarg);
                break;
            case 'd':
                driver_id = ao_driver_id(optarg);
                if (driver_id < 0) {
                    fprintf(stderr, "Invalid output driver \"%s\"\n", optarg);
                    status = 1;
                    goto done;
                }
                break;
            case 'f':
                out_filename = optarg;
                break;
            case 'h':
                usage(argv[0]);
                goto done;
            case 'o':
                add_driver_option(optarg);
                break;
            case 'r':
                repeat = 1;
                break;
            case 'v':
                verbose = 1;
                break;
            default:
                goto done;
        }
    }
    argc -= optind;
    argv += optind;

    for (opt = 0; opt < argc; ++opt) {
        if (play_file(argv[opt], &par)) {
            status = 1;
            goto done;
        }
    }

    if (repeat) {
        optind = 0;
        goto again;
    }

    done:

    if (device)
        ao_close(device);
    if (buffer)
        free(buffer);

    ao_free_options(device_options);
    ao_shutdown();

    return status;
}