player/Control: Play*() returns Error information
This commit is contained in:
parent
2065e32904
commit
fb547260d1
@ -123,20 +123,20 @@ struct Partition final : private PlayerListener, private MixerListener {
|
|||||||
playlist.Stop(pc);
|
playlist.Stop(pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayPosition(int position) {
|
bool PlayPosition(int position, Error &error) {
|
||||||
playlist.PlayPosition(pc, position);
|
return playlist.PlayPosition(pc, position, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayId(int id) {
|
bool PlayId(int id, Error &error) {
|
||||||
playlist.PlayId(pc, id);
|
return playlist.PlayId(pc, id, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayNext() {
|
bool PlayNext(Error &error) {
|
||||||
playlist.PlayNext(pc);
|
return playlist.PlayNext(pc, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayPrevious() {
|
bool PlayPrevious(Error &error) {
|
||||||
playlist.PlayPrevious(pc);
|
return playlist.PlayPrevious(pc, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SeekSongPosition(unsigned song_position,
|
bool SeekSongPosition(unsigned song_position,
|
||||||
|
@ -60,16 +60,22 @@ CommandResult
|
|||||||
handle_play(Client &client, Request args, gcc_unused Response &r)
|
handle_play(Client &client, Request args, gcc_unused Response &r)
|
||||||
{
|
{
|
||||||
int song = args.ParseOptional(0, -1);
|
int song = args.ParseOptional(0, -1);
|
||||||
client.partition.PlayPosition(song);
|
|
||||||
return CommandResult::OK;
|
Error error;
|
||||||
|
return client.partition.PlayPosition(song, error)
|
||||||
|
? CommandResult::OK
|
||||||
|
: print_error(r, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResult
|
CommandResult
|
||||||
handle_playid(Client &client, Request args, gcc_unused Response &r)
|
handle_playid(Client &client, Request args, gcc_unused Response &r)
|
||||||
{
|
{
|
||||||
int id = args.ParseOptional(0, -1);
|
int id = args.ParseOptional(0, -1);
|
||||||
client.partition.PlayId(id);
|
|
||||||
return CommandResult::OK;
|
Error error;
|
||||||
|
return client.partition.PlayId(id, error)
|
||||||
|
? CommandResult::OK
|
||||||
|
: print_error(r, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResult
|
CommandResult
|
||||||
@ -212,18 +218,24 @@ handle_next(Client &client, gcc_unused Request args, gcc_unused Response &r)
|
|||||||
const bool single = playlist.queue.single;
|
const bool single = playlist.queue.single;
|
||||||
playlist.queue.single = false;
|
playlist.queue.single = false;
|
||||||
|
|
||||||
client.partition.PlayNext();
|
Error error;
|
||||||
|
bool success = client.partition.PlayNext(error);
|
||||||
|
|
||||||
playlist.queue.single = single;
|
playlist.queue.single = single;
|
||||||
return CommandResult::OK;
|
|
||||||
|
return success
|
||||||
|
? CommandResult::OK
|
||||||
|
: print_error(r, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResult
|
CommandResult
|
||||||
handle_previous(Client &client, gcc_unused Request args,
|
handle_previous(Client &client, gcc_unused Request args,
|
||||||
gcc_unused Response &r)
|
gcc_unused Response &r)
|
||||||
{
|
{
|
||||||
client.partition.PlayPrevious();
|
Error error;
|
||||||
return CommandResult::OK;
|
return client.partition.PlayPrevious(error)
|
||||||
|
? CommandResult::OK
|
||||||
|
: print_error(r, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResult
|
CommandResult
|
||||||
|
@ -49,18 +49,20 @@ PlayerControl::~PlayerControl()
|
|||||||
delete tagged_song;
|
delete tagged_song;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
PlayerControl::Play(DetachedSong *song)
|
PlayerControl::Play(DetachedSong *song, Error &error_r)
|
||||||
{
|
{
|
||||||
assert(song != nullptr);
|
assert(song != nullptr);
|
||||||
|
|
||||||
const ScopeLock protect(mutex);
|
const ScopeLock protect(mutex);
|
||||||
SeekLocked(song, SongTime::zero(), IgnoreError());
|
bool success = SeekLocked(song, SongTime::zero(), error_r);
|
||||||
|
|
||||||
if (state == PlayerState::PAUSE)
|
if (success && state == PlayerState::PAUSE)
|
||||||
/* if the player was paused previously, we need to
|
/* if the player was paused previously, we need to
|
||||||
unpause it */
|
unpause it */
|
||||||
PauseLocked();
|
PauseLocked();
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -311,7 +311,7 @@ public:
|
|||||||
* @param song the song to be queued; the given instance will
|
* @param song the song to be queued; the given instance will
|
||||||
* be owned and freed by the player
|
* be owned and freed by the player
|
||||||
*/
|
*/
|
||||||
void Play(DetachedSong *song);
|
bool Play(DetachedSong *song, Error &error);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* see PlayerCommand::CANCEL
|
* see PlayerCommand::CANCEL
|
||||||
|
@ -152,8 +152,8 @@ playlist::UpdateQueuedSong(PlayerControl &pc, const DetachedSong *prev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
playlist::PlayOrder(PlayerControl &pc, int order)
|
playlist::PlayOrder(PlayerControl &pc, int order, Error &error)
|
||||||
{
|
{
|
||||||
playing = true;
|
playing = true;
|
||||||
queued = -1;
|
queued = -1;
|
||||||
@ -162,10 +162,14 @@ playlist::PlayOrder(PlayerControl &pc, int order)
|
|||||||
|
|
||||||
FormatDebug(playlist_domain, "play %i:\"%s\"", order, song.GetURI());
|
FormatDebug(playlist_domain, "play %i:\"%s\"", order, song.GetURI());
|
||||||
|
|
||||||
pc.Play(new DetachedSong(song));
|
|
||||||
current = order;
|
current = order;
|
||||||
|
|
||||||
|
if (!pc.Play(new DetachedSong(song), error))
|
||||||
|
return false;
|
||||||
|
|
||||||
SongStarted();
|
SongStarted();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -224,7 +228,8 @@ playlist::ResumePlayback(PlayerControl &pc)
|
|||||||
Stop(pc);
|
Stop(pc);
|
||||||
else
|
else
|
||||||
/* continue playback at the next song */
|
/* continue playback at the next song */
|
||||||
PlayNext(pc);
|
/* TODO: log error? */
|
||||||
|
PlayNext(pc, IgnoreError());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -262,15 +262,15 @@ public:
|
|||||||
|
|
||||||
void Stop(PlayerControl &pc);
|
void Stop(PlayerControl &pc);
|
||||||
|
|
||||||
void PlayPosition(PlayerControl &pc, int position);
|
bool PlayPosition(PlayerControl &pc, int position, Error &error);
|
||||||
|
|
||||||
void PlayOrder(PlayerControl &pc, int order);
|
bool PlayOrder(PlayerControl &pc, int order, Error &error);
|
||||||
|
|
||||||
void PlayId(PlayerControl &pc, int id);
|
bool PlayId(PlayerControl &pc, int id, Error &error);
|
||||||
|
|
||||||
void PlayNext(PlayerControl &pc);
|
bool PlayNext(PlayerControl &pc, Error &error);
|
||||||
|
|
||||||
void PlayPrevious(PlayerControl &pc);
|
bool PlayPrevious(PlayerControl &pc, Error &error);
|
||||||
|
|
||||||
bool SeekSongOrder(PlayerControl &pc,
|
bool SeekSongOrder(PlayerControl &pc,
|
||||||
unsigned song_order,
|
unsigned song_order,
|
||||||
|
@ -56,8 +56,8 @@ playlist::Stop(PlayerControl &pc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
playlist::PlayPosition(PlayerControl &pc, int song)
|
playlist::PlayPosition(PlayerControl &pc, int song, Error &error)
|
||||||
{
|
{
|
||||||
pc.LockClearError();
|
pc.LockClearError();
|
||||||
|
|
||||||
@ -66,13 +66,13 @@ playlist::PlayPosition(PlayerControl &pc, int song)
|
|||||||
/* play any song ("current" song, or the first song */
|
/* play any song ("current" song, or the first song */
|
||||||
|
|
||||||
if (queue.IsEmpty())
|
if (queue.IsEmpty())
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
if (playing) {
|
if (playing) {
|
||||||
/* already playing: unpause playback, just in
|
/* already playing: unpause playback, just in
|
||||||
case it was paused, and return */
|
case it was paused, and return */
|
||||||
pc.LockSetPause(false);
|
pc.LockSetPause(false);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* select a song: "current" song, or the first one */
|
/* select a song: "current" song, or the first one */
|
||||||
@ -102,29 +102,30 @@ playlist::PlayPosition(PlayerControl &pc, int song)
|
|||||||
stop_on_error = false;
|
stop_on_error = false;
|
||||||
error_count = 0;
|
error_count = 0;
|
||||||
|
|
||||||
PlayOrder(pc, i);
|
return PlayOrder(pc, i, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
playlist::PlayId(PlayerControl &pc, int id)
|
playlist::PlayId(PlayerControl &pc, int id, Error &error)
|
||||||
{
|
{
|
||||||
if (id == -1) {
|
if (id == -1)
|
||||||
PlayPosition(pc, id);
|
return PlayPosition(pc, id, error);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int song = queue.IdToPosition(id);
|
int song = queue.IdToPosition(id);
|
||||||
if (song < 0)
|
if (song < 0)
|
||||||
throw PlaylistError::NoSuchSong();
|
throw PlaylistError::NoSuchSong();
|
||||||
|
|
||||||
return PlayPosition(pc, song);
|
return PlayPosition(pc, song, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
playlist::PlayNext(PlayerControl &pc)
|
playlist::PlayNext(PlayerControl &pc, Error &error)
|
||||||
{
|
{
|
||||||
if (!playing)
|
if (!playing) {
|
||||||
return;
|
error.Set(playlist_domain, int(PlaylistResult::NOT_PLAYING),
|
||||||
|
"Not playing");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
assert(!queue.IsEmpty());
|
assert(!queue.IsEmpty());
|
||||||
assert(queue.IsValidOrder(current));
|
assert(queue.IsValidOrder(current));
|
||||||
@ -158,19 +159,25 @@ playlist::PlayNext(PlayerControl &pc)
|
|||||||
discard them anyway */
|
discard them anyway */
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayOrder(pc, next_order);
|
if (!PlayOrder(pc, next_order, error))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Consume mode removes each played songs. */
|
/* Consume mode removes each played songs. */
|
||||||
if (queue.consume)
|
if (queue.consume)
|
||||||
DeleteOrder(pc, old_current);
|
DeleteOrder(pc, old_current);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
playlist::PlayPrevious(PlayerControl &pc)
|
playlist::PlayPrevious(PlayerControl &pc, Error &error)
|
||||||
{
|
{
|
||||||
if (!playing)
|
if (!playing) {
|
||||||
return;
|
error.Set(playlist_domain, int(PlaylistResult::NOT_PLAYING),
|
||||||
|
"Not playing");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
assert(!queue.IsEmpty());
|
assert(!queue.IsEmpty());
|
||||||
|
|
||||||
@ -187,7 +194,7 @@ playlist::PlayPrevious(PlayerControl &pc)
|
|||||||
order = current;
|
order = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayOrder(pc, order);
|
return PlayOrder(pc, order, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -239,7 +239,8 @@ playlist::DeleteInternal(PlayerControl &pc,
|
|||||||
|
|
||||||
if (current >= 0 && !paused)
|
if (current >= 0 && !paused)
|
||||||
/* play the song after the deleted one */
|
/* play the song after the deleted one */
|
||||||
PlayOrder(pc, current);
|
/* TODO: log error? */
|
||||||
|
PlayOrder(pc, current, IgnoreError());
|
||||||
else {
|
else {
|
||||||
/* stop the player */
|
/* stop the player */
|
||||||
|
|
||||||
|
@ -196,7 +196,8 @@ playlist_state_restore(const char *line, TextFile &file,
|
|||||||
if (state == PlayerState::STOP /* && config_option */)
|
if (state == PlayerState::STOP /* && config_option */)
|
||||||
playlist.current = current;
|
playlist.current = current;
|
||||||
else if (seek_time.count() == 0)
|
else if (seek_time.count() == 0)
|
||||||
playlist.PlayPosition(pc, current);
|
/* TODO: log error? */
|
||||||
|
playlist.PlayPosition(pc, current, IgnoreError());
|
||||||
else
|
else
|
||||||
playlist.SeekSongPosition(pc, current, seek_time,
|
playlist.SeekSongPosition(pc, current, seek_time,
|
||||||
IgnoreError());
|
IgnoreError());
|
||||||
|
Loading…
Reference in New Issue
Block a user