From 025cb3b9e384883c90255173bc4f2fcb4dd74106 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 28 Apr 2015 22:06:22 +0200 Subject: command: let sub_reload remove the old track first In the most simple case, this prevents the track ID from changing. One disadvantage is that if the file fails loading, the track is gone for good and would have to be re-added explicitly by the user. --- player/command.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'player/command.c') diff --git a/player/command.c b/player/command.c index 4b1979b14d..9fbe6fd694 100644 --- a/player/command.c +++ b/player/command.c @@ -4549,15 +4549,17 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re case MP_CMD_AUDIO_RELOAD: { int type = cmd->id == MP_CMD_SUB_RELOAD ? STREAM_SUB : STREAM_AUDIO; struct track *t = mp_track_by_tid(mpctx, type, cmd->args[0].v.i); + struct track *nt = NULL; if (t && t->is_external && t->external_filename) { - struct track *nt = mp_add_external_file(mpctx, t->external_filename, - type); - if (nt) { - mp_remove_track(mpctx, t); - mp_switch_track(mpctx, nt->type, nt); - print_track_list(mpctx); - return 0; - } + char *filename = talloc_strdup(NULL, t->external_filename); + mp_remove_track(mpctx, t); + nt = mp_add_external_file(mpctx, filename, type); + talloc_free(filename); + } + if (nt) { + mp_switch_track(mpctx, nt->type, nt); + print_track_list(mpctx); + return 0; } return -1; } -- cgit v1.2.3