summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-04-28 22:06:22 +0200
committerwm4 <wm4@nowhere>2015-04-28 22:06:22 +0200
commit025cb3b9e384883c90255173bc4f2fcb4dd74106 (patch)
tree97cb546e29f8f6b44f8ebcedb93844385d40e331 /player/command.c
parent9795216d8a07bea3c2492c1ec236f863cc1d2d9b (diff)
downloadmpv-025cb3b9e384883c90255173bc4f2fcb4dd74106.tar.bz2
mpv-025cb3b9e384883c90255173bc4f2fcb4dd74106.tar.xz
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.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c18
1 files changed, 10 insertions, 8 deletions
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;
}