GCC Code Coverage Report


Directory: ./
File: commands/PlaylistCommands.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 254 283 89.8%
Functions: 31 31 100.0%
Branches: 384 792 48.5%

Line Branch Exec Source
1 /*
2 * This file is part of the Falcon Player (FPP) and is Copyright (C)
3 * 2013-2022 by the Falcon Player Developers.
4 *
5 * The Falcon Player (FPP) is free software, and is covered under
6 * multiple Open Source licenses. Please see the included 'LICENSES'
7 * file for descriptions of what files are covered by each license.
8 *
9 * This source file is covered under the LGPL v2.1 as described in the
10 * included LICENSE.LGPL file.
11 */
12
13 #include "fpp-pch.h"
14
15 #include "../common.h"
16 #include "../log.h"
17 #include <thread> // std::this_thread::sleep_for -- needed directly for NOPCH builds
18
19 #include "Player.h"
20 #include "PlaylistCommands.h"
21 #include "Scheduler.h"
22
23 // A playlist name is the one argument every command in this file needs, and an
24 // empty one is never a playlist: it is a UI that posted with nothing selected,
25 // or a %VAR:name% that resolved to nothing. CommandManager's missing-argument
26 // check (invokeCommand(), Commands.cpp) only catches an argument that is not
27 // there at all - an explicit "" still reaches run() and gets treated as a name.
28 // That is how "Start Playlist At Item" with an empty name matched the (equally
29 // empty) name of the playlist the scheduler thought should be running, deferred
30 // to the scheduler, started nothing, and still returned success, leaving the web
31 // UI to report "Playlist Started" with the player sitting idle (issue #2944).
32 2126 static std::unique_ptr<Command::Result> MissingPlaylistName(const std::vector<std::string>& args,
33 const std::string& command) {
34
5/6
✓ Branch 0 taken 2126 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 2119 times.
✓ Branch 4 taken 7 times.
✓ Branch 5 taken 2119 times.
2126 if (args.empty() || args[0].empty()) {
35 7 LogWarn(VB_COMMAND, "Ignoring \"%s\" - no playlist name was given\n", command.c_str());
36
3/6
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
7 return std::make_unique<Command::ErrorResult>("\"" + command + "\" requires a playlist name");
37 }
38 2119 return nullptr;
39 }
40
41 2652 StopPlaylistCommand::StopPlaylistCommand() :
42
2/4
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
5304 Command("Stop Now") {
43 2652 }
44 784 std::unique_ptr<Command::Result> StopPlaylistCommand::run(const std::vector<std::string>& args) {
45 784 Player::INSTANCE.StopNow(1);
46 784 return std::make_unique<Command::Result>("Stopped");
47 }
48
49 2652 StopGracefullyPlaylistCommand::StopGracefullyPlaylistCommand() :
50
2/4
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
5304 Command("Stop Gracefully") {
51 // Optional: run() has always treated a missing argument as "false", and
52 // "Stop Gracefully" with no arguments at all is a normal way to call it.
53 // Saying so here is what keeps CommandManager's missing-argument check
54 // (invokeCommand(), Commands.cpp) from refusing that call.
55
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("loop", "bool", "After Loop", true).setDefaultValue("false"));
56 2652 }
57 9 std::unique_ptr<Command::Result> StopGracefullyPlaylistCommand::run(const std::vector<std::string>& args) {
58 9 bool loop = false;
59
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
9 if (args.size()) {
60
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
4 loop = args[0] == "true" || args[0] == "1";
61 }
62 9 Player::INSTANCE.StopGracefully(1, loop);
63 9 return std::make_unique<Command::Result>("Stopping");
64 }
65
66 2652 RestartPlaylistCommand::RestartPlaylistCommand() :
67
2/4
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
5304 Command("Restart Playlist Item") {
68 2652 }
69 8146 std::unique_ptr<Command::Result> RestartPlaylistCommand::run(const std::vector<std::string>& args) {
70 8146 Player::INSTANCE.RestartItem();
71 8146 return std::make_unique<Command::Result>("Restarting");
72 }
73
74 2652 NextPlaylistCommand::NextPlaylistCommand() :
75
2/4
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
5304 Command("Next Playlist Item") {
76 2652 }
77 8187 std::unique_ptr<Command::Result> NextPlaylistCommand::run(const std::vector<std::string>& args) {
78 8187 Player::INSTANCE.NextItem();
79 8187 return std::make_unique<Command::Result>("Next Item Playing");
80 }
81
82 2652 PrevPlaylistCommand::PrevPlaylistCommand() :
83
2/4
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
5304 Command("Prev Playlist Item") {
84 2652 }
85 8177 std::unique_ptr<Command::Result> PrevPlaylistCommand::run(const std::vector<std::string>& args) {
86 8177 Player::INSTANCE.PrevItem();
87 8177 return std::make_unique<Command::Result>("Prev Item Playing");
88 }
89
90 2652 StartPlaylistCommand::StartPlaylistCommand() :
91
2/4
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
5304 Command("Start Playlist") {
92
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("name", "string", "Playlist Name")
93
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setContentListUrl("api/playlists/playable"));
94
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("repeat", "bool", "Repeat", true).setDefaultValue("false"));
95
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("ifNotRunning", "bool", "If Not Running", true)
96
1/2
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
2652 .setDefaultValue("false")
97
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setHelp("Checks to see if this exact item is already running and "
98 "prevents it from running again."));
99
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("scheduleProtected", "bool", "Protected from Schedule Override", true).setDefaultValue("false"));
100 2652 }
101 1390 std::unique_ptr<Command::Result> StartPlaylistCommand::run(const std::vector<std::string>& args) {
102
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1389 times.
1390 if (auto missing = MissingPlaylistName(args, name)) {
103 1 return missing;
104 1389 }
105 1389 bool r = false;
106 1389 bool iNR = false;
107 1389 bool scheduleProtected = false;
108
1/2
✓ Branch 0 taken 1389 times.
✗ Branch 1 not taken.
1389 if (args.size() > 1) {
109
3/4
✓ Branch 0 taken 1112 times.
✓ Branch 1 taken 277 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1112 times.
1389 r = args[1] == "true" || args[1] == "1";
110 }
111
1/2
✓ Branch 0 taken 1389 times.
✗ Branch 1 not taken.
1389 if (args.size() > 2) {
112
3/4
✓ Branch 0 taken 1388 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1388 times.
1389 iNR = args[2] == "true" || args[2] == "1";
113 }
114
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1384 times.
1389 if (args.size() > 3) {
115
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
5 scheduleProtected = args[3] == "true" || args[3] == "1";
116 }
117
8/12
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1388 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1388 times.
✓ Branch 8 taken 1388 times.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
1389 if (!iNR || args[0] != Player::INSTANCE.GetPlaylistName()) {
118 // The stop and the wait below are part of the start: the scheduler
119 // must not act on the player being idle in between.
120
1/2
✓ Branch 0 taken 1388 times.
✗ Branch 1 not taken.
1388 Player::SwitchScope switching;
121
3/6
✓ Branch 0 taken 1388 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1388 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1388 times.
✗ Branch 5 not taken.
1388 LogInfo(VB_COMMAND, "StartPlaylistCommand: Requesting playlist '%s', current='%s', status=%d\n",
122 args[0].c_str(), Player::INSTANCE.GetPlaylistName().c_str(), Player::INSTANCE.GetStatus());
123
124 // Always stop if not idle to avoid deferred start mechanism
125 // Every level: a single StopNow ends only a playlist inserted into the
126 // running one, which then resumes until the start stops it as well.
127
3/4
✓ Branch 0 taken 1388 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
✓ Branch 3 taken 1236 times.
1388 if (Player::INSTANCE.GetStatus() != FPP_STATUS_IDLE) {
128
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 LogInfo(VB_COMMAND, "StartPlaylistCommand: Stopping current playlist\n");
129 // Clear force-stopped flag to allow scheduler to work if needed
130
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 Player::INSTANCE.ClearForceStopped();
131
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 Player::INSTANCE.StopNowAllLevels(1);
132 // Brief wait to let stop complete - don't wait too long to avoid scheduler interference
133
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 std::this_thread::sleep_for(std::chrono::milliseconds(150));
134
2/4
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
152 LogInfo(VB_COMMAND, "StartPlaylistCommand: After stop wait, status=%d\n", Player::INSTANCE.GetStatus());
135 }
136
1/2
✓ Branch 0 taken 1388 times.
✗ Branch 1 not taken.
1388 Player::INSTANCE.StartPlaylist(args[0], r, -1, -1, -1, !scheduleProtected);
137 1388 }
138 1389 return std::make_unique<Command::Result>("Playlist Starting");
139 }
140
141 2652 TogglePlaylistCommand::TogglePlaylistCommand() :
142
2/4
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
5304 Command("Toggle Playlist") {
143
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("name", "string", "Playlist Name")
144
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setContentListUrl("api/playlists/playable"));
145
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("repeat", "bool", "Repeat", true).setDefaultValue("false"));
146
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("stop", "string", "Stop Type")
147
1/2
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
7956 .setContentList({ "Gracefully", "After Loop", "Now" })
148
2/4
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
2652 .setDefaultValue("Gracefully"));
149 2652 }
150 3 std::unique_ptr<Command::Result> TogglePlaylistCommand::run(const std::vector<std::string>& args) {
151
3/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if (auto missing = MissingPlaylistName(args, name)) {
152 1 return missing;
153 2 }
154 2 bool r = false;
155
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 std::string stopType = "Gracefully";
156
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (args.size() > 1) {
157
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
2 r = args[1] == "true" || args[1] == "1";
158 }
159
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (args.size() > 2) {
160
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 stopType = args[2];
161 }
162
9/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
2 if (Player::INSTANCE.IsPlaying() && Player::INSTANCE.GetPlaylistName() == args[0]) {
163
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (stopType == "Now") {
164
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 Player::INSTANCE.StopNowAllLevels(1);
165 ✗ } else if (stopType == "After Loop") {
166 ✗ Player::INSTANCE.StopGracefully(true, true);
167 } else {
168 ✗ Player::INSTANCE.StopGracefully(true, false);
169 }
170
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 return std::make_unique<Command::Result>("Playlist Stopping");
171 }
172
173
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 LogInfo(VB_COMMAND, "TogglePlaylistCommand: Requesting playlist '%s', current='%s', status=%d\n",
174 args[0].c_str(), Player::INSTANCE.GetPlaylistName().c_str(), Player::INSTANCE.GetStatus());
175
176
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 Player::SwitchScope switching; // see StartPlaylistCommand
177 // If a different playlist is playing, stop it first to avoid race conditions
178
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (Player::INSTANCE.GetStatus() != FPP_STATUS_IDLE) {
179 ✗ LogInfo(VB_COMMAND, "TogglePlaylistCommand: Stopping current playlist\n");
180 ✗ Player::INSTANCE.ClearForceStopped();
181 ✗ Player::INSTANCE.StopNow(1);
182 ✗ std::this_thread::sleep_for(std::chrono::milliseconds(150));
183 ✗ LogInfo(VB_COMMAND, "TogglePlaylistCommand: After stop wait, status=%d\n", Player::INSTANCE.GetStatus());
184 }
185
186
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 Player::INSTANCE.StartPlaylist(args[0], r);
187
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 return std::make_unique<Command::Result>("Playlist Starting");
188 2 }
189
190 2652 StartPlaylistAtCommand::StartPlaylistAtCommand() :
191
2/4
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
5304 Command("Start Playlist At Item") {
192
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("name", "string", "Playlist Name")
193
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setContentListUrl("api/playlists"));
194
5/10
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
15912 args.push_back(CommandArg("item", "int", "Item Index").setRange(1, 100));
195
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("repeat", "bool", "Repeat", true).setDefaultValue("false"));
196
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("ifNotRunning", "bool", "If Not Running", true)
197
1/2
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
2652 .setDefaultValue("false")
198
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setHelp("Checks to see if this exact item is already running and "
199 "prevents it from running again."));
200
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("scheduleProtected", "bool", "Protected from Schedule Override", true).setDefaultValue("false"));
201 2652 }
202 42 std::unique_ptr<Command::Result> StartPlaylistAtCommand::run(const std::vector<std::string>& args) {
203
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 41 times.
42 if (auto missing = MissingPlaylistName(args, name)) {
204 1 return missing;
205 41 }
206 41 bool r = false;
207 41 bool scheduleProtected = false;
208
209 41 int idx = 1;
210
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 1 times.
41 if (args.size() > 1) {
211 40 idx = std::atoi(args[1].c_str());
212 }
213 41 bool iNR = false;
214
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 1 times.
41 if (args.size() > 2) {
215
3/4
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33 times.
40 r = args[2] == "true" || args[2] == "1";
216 }
217
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 1 times.
41 if (args.size() > 3) {
218
2/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
40 iNR = args[3] == "true" || args[3] == "1";
219 }
220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (args.size() > 4) {
221 ✗ scheduleProtected = args[4] == "true" || args[4] == "1";
222 }
223
3/12
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 41 times.
✓ Branch 8 taken 41 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
41 if (!iNR || args[0] != Player::INSTANCE.GetPlaylistName()) {
224 41 int scheduledRepeat = 0;
225
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 std::string playlistName = scheduler->GetPlaylistThatShouldBePlaying(scheduledRepeat);
226 41 bool repeat = scheduledRepeat;
227
228
3/6
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41 times.
✗ Branch 5 not taken.
41 LogInfo(VB_COMMAND, "StartPlaylistAtCommand: args[0]='%s', status=%d, currentPlaylist='%s', scheduledPlaylist='%s'\n",
229 args[0].c_str(), Player::INSTANCE.GetStatus(),
230 Player::INSTANCE.GetPlaylistName().c_str(), playlistName.c_str());
231
232 // Only defer to scheduler if we're idle AND the requested playlist matches what should be scheduled
233 // AND it's not currently being played. This prevents the race condition where we're playing a
234 // scheduled background playlist and want to start a different playlist via API.
235
3/4
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 28 times.
70 if ((Player::INSTANCE.GetStatus() == FPP_STATUS_IDLE) &&
236
5/6
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 40 times.
70 (args[0] == playlistName) &&
237 (r == repeat)) {
238
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogInfo(VB_COMMAND, "StartPlaylistAtCommand: Deferring to scheduler\n");
239 // Allow the scheduler to restart even if force stopped
240
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 Player::INSTANCE.ClearForceStopped();
241
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 scheduler->CheckIfShouldBePlayingNow(1);
242 } else {
243
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 Player::SwitchScope switching; // see StartPlaylistCommand
244 // Always directly start the playlist if:
245 // 1. Something is already playing (even if it's the scheduled playlist)
246 // 2. The requested playlist doesn't match what's scheduled
247 // 3. The repeat mode doesn't match
248
249 // If playing a different playlist, stop the current one first
250
3/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 28 times.
52 if ((Player::INSTANCE.GetStatus() != FPP_STATUS_IDLE) &&
251
7/10
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 28 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 38 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
52 (Player::INSTANCE.GetPlaylistName() != args[0])) {
252
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 LogInfo(VB_COMMAND, "StartPlaylistAtCommand: Stopping current playlist '%s' before starting '%s'\n",
253 Player::INSTANCE.GetPlaylistName().c_str(), args[0].c_str());
254
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Player::INSTANCE.StopNowAllLevels(1);
255 }
256
257
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 LogInfo(VB_COMMAND, "StartPlaylistAtCommand: Starting playlist '%s'\n", args[0].c_str());
258
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 Player::INSTANCE.StartPlaylist(args[0], r, idx - 1, -1, -1, !scheduleProtected);
259 40 }
260 41 }
261 41 return std::make_unique<Command::Result>("Playlist Starting");
262 }
263
264 2652 StartPlaylistAtRandomCommand::StartPlaylistAtRandomCommand() :
265
2/4
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
5304 Command("Start Playlist At Random Item") {
266
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("name", "string", "Playlist Name")
267
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setContentListUrl("api/playlists"));
268
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("repeat", "bool", "Repeat", true).setDefaultValue("false"));
269
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("ifNotRunning", "bool", "If Not Running", true)
270
1/2
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
2652 .setDefaultValue("false")
271
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setHelp("Checks to see if this exact item is already running and "
272 "prevents it from running again."));
273 2652 }
274 1 std::unique_ptr<Command::Result> StartPlaylistAtRandomCommand::run(const std::vector<std::string>& args) {
275
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (auto missing = MissingPlaylistName(args, name)) {
276 1 return missing;
277 ✗ }
278 ✗ bool r = false;
279 ✗ bool iNR = false;
280 ✗ if (args.size() > 1) {
281 ✗ r = args[1] == "true" || args[1] == "1";
282 }
283 ✗ if (args.size() > 2) {
284 ✗ iNR = args[2] == "true" || args[2] == "1";
285 }
286 ✗ if (!iNR || args[0] != Player::INSTANCE.GetPlaylistName()) {
287 ✗ Player::SwitchScope switching; // see StartPlaylistCommand
288 ✗ LogInfo(VB_COMMAND, "StartPlaylistAtRandomCommand: Requesting playlist '%s', current='%s', status=%d\n",
289 args[0].c_str(), Player::INSTANCE.GetPlaylistName().c_str(), Player::INSTANCE.GetStatus());
290
291 // Always stop if not idle to avoid deferred start mechanism
292 ✗ if (Player::INSTANCE.GetStatus() != FPP_STATUS_IDLE) {
293 ✗ LogInfo(VB_COMMAND, "StartPlaylistAtRandomCommand: Stopping current playlist\n");
294 // Clear force-stopped flag to allow scheduler to work if needed
295 ✗ Player::INSTANCE.ClearForceStopped();
296 ✗ Player::INSTANCE.StopNowAllLevels(1);
297 // Brief wait to let stop complete - don't wait too long to avoid scheduler interference
298 ✗ std::this_thread::sleep_for(std::chrono::milliseconds(150));
299 ✗ LogInfo(VB_COMMAND, "StartPlaylistAtRandomCommand: After stop wait, status=%d\n", Player::INSTANCE.GetStatus());
300 }
301 ✗ Player::INSTANCE.StartPlaylist(args[0], r, -2);
302 ✗ }
303 ✗ return std::make_unique<Command::Result>("Playlist Starting");
304 }
305
306 2652 InsertPlaylistCommand::InsertPlaylistCommand() :
307
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
10608 Command("Insert Playlist After Current", "After the current item of the currently running playlist is complete, run the new playlist. When complete, resumes the original playlist at the next position.") {
308
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("name", "string", "Playlist Name")
309
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setContentListUrl("api/playlists/playable"));
310
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("startItem", "int", "Start Item Index", true).setRange(-1, 100).setDefaultValue("-1"));
311
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("endItem", "int", "End Item Index", true).setRange(-1, 100).setDefaultValue("-1"));
312
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("ifNotRunning", "bool", "If Not Running", true)
313
1/2
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
2652 .setDefaultValue("false")
314
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setHelp("Checks to see if this exact item is already running and "
315 "prevents it from running again."));
316 2652 }
317 29 std::unique_ptr<Command::Result> InsertPlaylistCommand::run(const std::vector<std::string>& args) {
318
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 28 times.
29 if (auto missing = MissingPlaylistName(args, name)) {
319 1 return missing;
320 28 }
321 28 int start = -1;
322 28 int end = -1;
323 28 bool iNR = false;
324
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if (args.size() > 1) {
325 28 start = std::atoi(args[1].c_str());
326 }
327
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if (args.size() > 2) {
328 28 end = std::atoi(args[2].c_str());
329 }
330
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 6 times.
28 if (args.size() > 3) {
331
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
22 iNR = args[3] == "true" || args[3] == "1";
332 }
333
3/12
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 28 times.
✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
28 if (!iNR || args[0] != Player::INSTANCE.GetPlaylistName()) {
334 28 Player::INSTANCE.InsertPlaylistAsNext(args[0], start > 0 ? start - 1 : -1, end > 0 ? end - 1 : -1);
335 }
336 28 return std::make_unique<Command::Result>("Playlist Inserted");
337 }
338
339 2652 InsertPlaylistImmediate::InsertPlaylistImmediate() :
340
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
10608 Command("Insert Playlist Immediate", "If possible, pauses the currently running playlist and then runs the new playlist. When complete, resumes the original playlist where it was paused.") {
341
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("name", "string", "Playlist Name")
342
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setContentListUrl("api/playlists/playable"));
343
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("startItem", "int", "Start Item Index", true).setRange(0, 100).setDefaultValue("0"));
344
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("endItem", "int", "End Item Index", true).setRange(0, 100).setDefaultValue("0"));
345
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("ifNotRunning", "bool", "If Not Running", true)
346
1/2
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
2652 .setDefaultValue("false")
347
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setHelp("Checks to see if this exact item is already running and "
348 "prevents it from running again."));
349 2652 }
350 642 std::unique_ptr<Command::Result> InsertPlaylistImmediate::run(const std::vector<std::string>& args) {
351
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 641 times.
642 if (auto missing = MissingPlaylistName(args, name)) {
352 1 return missing;
353 641 }
354 641 int start = -1;
355 641 int end = -1;
356 641 bool iNR = false;
357
1/2
✓ Branch 0 taken 641 times.
✗ Branch 1 not taken.
641 if (args.size() > 1) {
358 641 start = std::atoi(args[1].c_str());
359 }
360
1/2
✓ Branch 0 taken 641 times.
✗ Branch 1 not taken.
641 if (args.size() > 2) {
361 641 end = std::atoi(args[2].c_str());
362 }
363
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 1 times.
641 if (args.size() > 3) {
364
2/4
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 640 times.
640 iNR = args[3] == "true" || args[3] == "1";
365 }
366
3/12
✗ Branch 0 not taken.
✓ Branch 1 taken 641 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 641 times.
✓ Branch 8 taken 641 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
641 if (!iNR || args[0] != Player::INSTANCE.GetPlaylistName()) {
367 641 Player::INSTANCE.InsertPlaylistImmediate(args[0], start > 0 ? start - 1 : -1, end > 0 ? end - 1 : -1);
368 }
369 641 return std::make_unique<Command::Result>("Playlist Inserted");
370 }
371
372 2652 InsertRandomItemFromPlaylistCommand::InsertRandomItemFromPlaylistCommand() :
373
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
10608 Command("Insert Random Item From Playlist", "Run a random item from the given playlist. When complete, resumes the original playlist.") {
374
4/8
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
18564 args.push_back(CommandArg("name", "string", "Playlist Name")
375
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
5304 .setContentListUrl("api/playlists/playable"));
376
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("immediate", "bool", "Immediate", true).setDefaultValue("false"));
377 2652 }
378 19 std::unique_ptr<Command::Result> InsertRandomItemFromPlaylistCommand::run(const std::vector<std::string>& args) {
379
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 18 times.
19 if (auto missing = MissingPlaylistName(args, name)) {
380 1 return missing;
381 18 }
382 18 bool immediate = false;
383
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (args.size() > 1) {
384
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18 immediate = args[1] == "true" || args[1] == "1";
385 }
386
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (immediate) {
387 18 Player::INSTANCE.InsertPlaylistImmediate(args[0], -2, 0);
388 } else {
389 ✗ Player::INSTANCE.InsertPlaylistAsNext(args[0], -2, 0);
390 }
391 18 return std::make_unique<Command::Result>("Playlist Inserted");
392 }
393
394 2652 PlaylistPauseCommand::PlaylistPauseCommand() :
395
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
10608 Command("Pause Playlist", "If possible, pauses the currently running playlist. This command can not be run from inside a playlist") {
396 2652 }
397 19 std::unique_ptr<Command::Result> PlaylistPauseCommand::run(const std::vector<std::string>& args) {
398 19 Player::INSTANCE.Pause();
399 19 return std::make_unique<Command::Result>("Playlist Paused");
400 }
401
402 2652 PlaylistResumeCommand::PlaylistResumeCommand() :
403
2/4
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
5304 Command("Resume Playlist") {
404 2652 }
405 16 std::unique_ptr<Command::Result> PlaylistResumeCommand::run(const std::vector<std::string>& args) {
406 16 Player::INSTANCE.Resume();
407 16 return std::make_unique<Command::Result>("Playlist Restarted");
408 }
409
410 2652 SetPlaylistRepeatCommand::SetPlaylistRepeatCommand() :
411
3/6
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
10608 Command("Set Playlist Repeat", "Turns repeat on or off for the running playlist. Nothing is started, stopped or restarted; the new setting is read when the playlist reaches the end of its current loop.") {
412
6/12
✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2652 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2652 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2652 times.
✗ Branch 11 not taken.
15912 args.push_back(CommandArg("repeat", "bool", "Repeat").setDefaultValue("true"));
413 2652 }
414 4 std::unique_ptr<Command::Result> SetPlaylistRepeatCommand::run(const std::vector<std::string>& args) {
415 4 bool repeat = true;
416
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (args.size()) {
417
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
4 repeat = args[0] == "true" || args[0] == "1";
418 }
419
420 // Repeat is a property of a *running* playlist, and only there. The idle
421 // playlist has been Cleanup()ed back to repeat=0, Play() reloads the value
422 // from the playlist file and then overwrites it with whatever the start
423 // command passed, and GetCurrentStatus() reports a hard-coded "0" while
424 // idle. Setting it now would therefore report success, never show up in
425 // /api/fppd/status, and be thrown away by the next start - so refuse
426 // instead of lying about it (issue #2971).
427
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (Player::INSTANCE.GetStatus() == FPP_STATUS_IDLE) {
428 1 LogWarn(VB_COMMAND, "Ignoring \"Set Playlist Repeat\" - no playlist is running\n");
429
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 return std::make_unique<Command::ErrorResult>("No playlist is running; pass the repeat flag to \"Start Playlist\" instead");
430 }
431
432
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 Player::INSTANCE.SetRepeat(repeat ? 1 : 0);
433
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 return std::make_unique<Command::Result>(repeat ? "Repeat Enabled" : "Repeat Disabled");
434 }
435