# HG changeset patch # User Michael Pavone # Date 1700209846 28800 # Node ID 02c04196c2da017a2569b6b0960f1d48814d25b6 # Parent 97f164d1f0f61c67828dfc8bed463e19dfe6f055 Fix mediaplayer play/pause handling diff -r 97f164d1f0f6 -r 02c04196c2da mediaplayer.c --- a/mediaplayer.c Wed Nov 15 23:23:52 2023 -0800 +++ b/mediaplayer.c Fri Nov 17 00:30:46 2023 -0800 @@ -682,8 +682,16 @@ static void gamepad_down(system_header *system, uint8_t pad, uint8_t button) { - if (button >= BUTTON_A && button <= BUTTON_C) { - media_player *player = (media_player *)system; + if (pad != 1) { + return; + } + media_player *player = (media_player *)system; + if (player->button_state[button]) { + //already pressed + return; + } + player->button_state[button] = 1; + if (button == BUTTON_A || button == BUTTON_C || button == BUTTON_START) { if (player->state == STATE_PAUSED) { player->state = STATE_PLAY; puts("Now playing"); @@ -696,6 +704,11 @@ static void gamepad_up(system_header *system, uint8_t pad, uint8_t button) { + if (pad != 1) { + return; + } + media_player *player = (media_player *)system; + player->button_state[button] = 0; } static void start_player(system_header *system, char *statefile) @@ -776,7 +789,7 @@ player->header.request_exit = request_exit; player->header.free_context = free_player; player->header.gamepad_down = gamepad_down; - player->header.gamepad_up = gamepad_down; + player->header.gamepad_up = gamepad_up; player->header.toggle_debug_view = toggle_debug_view; player->header.type = SYSTEM_MEDIA_PLAYER; player->header.info.name = strdup(media->name); diff -r 97f164d1f0f6 -r 02c04196c2da mediaplayer.h --- a/mediaplayer.h Wed Nov 15 23:23:52 2023 -0800 +++ b/mediaplayer.h Fri Nov 17 00:30:46 2023 -0800 @@ -8,6 +8,7 @@ #include "flac.h" #include "oscilloscope.h" #include "render_audio.h" +#include "io.h" typedef struct chip_info chip_info; typedef void (*chip_run_fun)(void *context, uint32_t cycle); @@ -48,6 +49,7 @@ uint8_t state; uint8_t media_type; uint8_t should_return; + uint8_t button_state[NUM_GAMEPAD_BUTTONS]; } media_player; media_player *alloc_media_player(system_media *media, uint32_t opts);