80 lines
1.9 KiB
C
80 lines
1.9 KiB
C
/*
|
|
player.c - backend player functions
|
|
|
|
This file is part of mp3fw.
|
|
|
|
mp3fw is free software: you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
option) any later version.
|
|
|
|
mp3fw is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with mp3fw. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "common.h"
|
|
|
|
/*
|
|
Positional Parameters
|
|
|
|
(user)$ mp3fw -p FILE
|
|
0 1 2
|
|
*/
|
|
|
|
|
|
static inline void
|
|
check_error(int status)
|
|
{
|
|
if (status < 0) {
|
|
printf("mpv API error: %s\n", mpv_error_string(status));
|
|
}
|
|
}
|
|
|
|
int
|
|
mp3fw_playfile(int argc, char *argv[])
|
|
{
|
|
|
|
/* struct EXTRACTOR_PluginList *plugins = EXTRACTOR_plugin_add_defaults(EXTRACTOR_OPTION_DEFAULT_POLICY);
|
|
EXTRACTOR_extract(plugins, argv[2], NULL, 0, &EXTRACTOR_meta_data_print, stdout);
|
|
EXTRACTOR_plugin_remove_all(plugins); */
|
|
|
|
if (argc != 3) {
|
|
printf("no audio file was passed into player\n");
|
|
return 1;
|
|
}
|
|
|
|
mpv_handle *ctx = mpv_create();
|
|
if (!ctx) {
|
|
printf("failed creating context\n");
|
|
return 1;
|
|
}
|
|
|
|
check_error(mpv_set_option_string(ctx, "input-default-bindings", "yes"));
|
|
mpv_set_option_string(ctx, "input-vo-keyboard", "yes");
|
|
int val = 1;
|
|
check_error(mpv_set_option(ctx, "osc", MPV_FORMAT_FLAG, &val));
|
|
|
|
check_error(mpv_initialize(ctx));
|
|
|
|
printf("loading file %s\n", argv[2]);
|
|
|
|
const char *cmd[] = {"loadfile", argv[2], NULL};
|
|
check_error(mpv_command(ctx, cmd));
|
|
|
|
do {
|
|
mpv_event *event = mpv_wait_event(ctx, 10000);
|
|
printf("event: %s\n", mpv_event_name(event->event_id));
|
|
if (event->event_id == MPV_EVENT_SHUTDOWN)
|
|
break;
|
|
}
|
|
|
|
while (1);
|
|
mpv_terminate_destroy(ctx);
|
|
return 0;
|
|
}
|