mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 12:07:09 +03:00
cspot duration
This commit is contained in:
@@ -32,9 +32,9 @@ message Artist {
|
||||
message Track {
|
||||
optional bytes gid = 1;
|
||||
optional string name = 2;
|
||||
optional sint32 duration = 0x7;
|
||||
optional Album album = 0x3;
|
||||
repeated Artist artist = 0x4;
|
||||
optional sint32 duration = 0x7;
|
||||
repeated Restriction restriction = 0xb;
|
||||
repeated AudioFile file = 0xc;
|
||||
repeated Track alternative = 0xd;
|
||||
|
||||
@@ -46,7 +46,7 @@ void AudioChunkManager::close() {
|
||||
|
||||
void AudioChunkManager::runTask() {
|
||||
std::scoped_lock lock(this->runningMutex);
|
||||
this->isRunning = true;
|
||||
this->isRunning = true;
|
||||
while (isRunning) {
|
||||
std::pair<std::vector<uint8_t>, bool> audioPair;
|
||||
if (this->audioChunkDataQueue.wtpop(audioPair, 100)) {
|
||||
|
||||
@@ -36,6 +36,7 @@ template int64_t PbReader::decodeFixed();
|
||||
|
||||
template uint32_t PbReader::decodeVarInt();
|
||||
template int64_t PbReader::decodeVarInt();
|
||||
template int32_t PbReader::decodeVarInt();
|
||||
template bool PbReader::decodeVarInt();
|
||||
|
||||
void PbReader::resetMaxPosition()
|
||||
|
||||
@@ -91,6 +91,10 @@ void decodeField(std::shared_ptr<PbReader> reader, AnyRef any)
|
||||
{
|
||||
*any.as<int64_t>() = reader->decodeVarInt<int64_t>();
|
||||
}
|
||||
else if (any.is<int32_t>())
|
||||
{
|
||||
*any.as<int32_t>() = reader->decodeVarInt<int32_t>();
|
||||
}
|
||||
else
|
||||
{
|
||||
reader->skip();
|
||||
|
||||
@@ -38,7 +38,7 @@ void SpircController::subscribe() {
|
||||
}
|
||||
|
||||
void SpircController::setPause(bool isPaused, bool notifyPlayer) {
|
||||
sendEvent(CSpotEventType::PLAY_PAUSE, isPaused);
|
||||
sendEvent(CSpotEventType::PLAY_PAUSE, isPaused);
|
||||
if (isPaused) {
|
||||
CSPOT_LOG(debug, "External pause command");
|
||||
if (notifyPlayer) player->pause();
|
||||
@@ -55,29 +55,29 @@ void SpircController::disconnect(void) {
|
||||
player->cancelCurrentTrack();
|
||||
state->setActive(false);
|
||||
notify();
|
||||
// Send the event at the end at it might be a last gasp
|
||||
sendEvent(CSpotEventType::DISC);
|
||||
// Send the event at the end at it might be a last gasp
|
||||
sendEvent(CSpotEventType::DISC);
|
||||
}
|
||||
|
||||
void SpircController::playToggle() {
|
||||
if (state->innerFrame.state->status.value() == PlayStatus::kPlayStatusPause) {
|
||||
setPause(false);
|
||||
} else {
|
||||
setPause(true);
|
||||
}
|
||||
if (state->innerFrame.state->status.value() == PlayStatus::kPlayStatusPause) {
|
||||
setPause(false);
|
||||
} else {
|
||||
setPause(true);
|
||||
}
|
||||
}
|
||||
|
||||
void SpircController::adjustVolume(int by) {
|
||||
if (state->innerFrame.device_state->volume.has_value()) {
|
||||
int volume = state->innerFrame.device_state->volume.value() + by;
|
||||
if (volume < 0) volume = 0;
|
||||
else if (volume > MAX_VOLUME) volume = MAX_VOLUME;
|
||||
setVolume(volume);
|
||||
}
|
||||
if (state->innerFrame.device_state->volume.has_value()) {
|
||||
int volume = state->innerFrame.device_state->volume.value() + by;
|
||||
if (volume < 0) volume = 0;
|
||||
else if (volume > MAX_VOLUME) volume = MAX_VOLUME;
|
||||
setVolume(volume);
|
||||
}
|
||||
}
|
||||
|
||||
void SpircController::setVolume(int volume) {
|
||||
setRemoteVolume(volume);
|
||||
setRemoteVolume(volume);
|
||||
player->setVolume(volume);
|
||||
configMan->save();
|
||||
}
|
||||
@@ -111,21 +111,21 @@ void SpircController::handleFrame(std::vector<uint8_t> &data) {
|
||||
// Pause the playback if another player took control
|
||||
if (state->isActive() &&
|
||||
state->remoteFrame.device_state->is_active.value()) {
|
||||
disconnect();
|
||||
disconnect();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MessageType::kMessageTypeSeek: {
|
||||
CSPOT_LOG(debug, "Seek command");
|
||||
sendEvent(CSpotEventType::SEEK, (int) state->remoteFrame.position.value());
|
||||
sendEvent(CSpotEventType::SEEK, (int) state->remoteFrame.position.value());
|
||||
state->updatePositionMs(state->remoteFrame.position.value());
|
||||
this->player->seekMs(state->remoteFrame.position.value());
|
||||
notify();
|
||||
break;
|
||||
}
|
||||
case MessageType::kMessageTypeVolume:
|
||||
sendEvent(CSpotEventType::VOLUME, (int) state->remoteFrame.volume.value());
|
||||
setVolume(state->remoteFrame.volume.value());
|
||||
sendEvent(CSpotEventType::VOLUME, (int) state->remoteFrame.volume.value());
|
||||
setVolume(state->remoteFrame.volume.value());
|
||||
break;
|
||||
case MessageType::kMessageTypePause:
|
||||
setPause(true);
|
||||
@@ -134,11 +134,11 @@ void SpircController::handleFrame(std::vector<uint8_t> &data) {
|
||||
setPause(false);
|
||||
break;
|
||||
case MessageType::kMessageTypeNext:
|
||||
sendEvent(CSpotEventType::NEXT);
|
||||
sendEvent(CSpotEventType::NEXT);
|
||||
nextSong();
|
||||
break;
|
||||
case MessageType::kMessageTypePrev:
|
||||
sendEvent(CSpotEventType::PREV);
|
||||
sendEvent(CSpotEventType::PREV);
|
||||
prevSong();
|
||||
break;
|
||||
case MessageType::kMessageTypeLoad: {
|
||||
@@ -182,7 +182,7 @@ void SpircController::handleFrame(std::vector<uint8_t> &data) {
|
||||
}
|
||||
|
||||
void SpircController::loadTrack(uint32_t position_ms, bool isPaused) {
|
||||
sendEvent(CSpotEventType::LOAD, (int) position_ms);
|
||||
sendEvent(CSpotEventType::LOAD, (int) position_ms);
|
||||
state->setPlaybackState(PlaybackState::Loading);
|
||||
std::function<void()> loadedLambda = [=]() {
|
||||
// Loading finished, notify that playback started
|
||||
@@ -201,7 +201,7 @@ void SpircController::sendEvent(CSpotEventType eventType, std::variant<TrackInfo
|
||||
if (eventHandler != nullptr) {
|
||||
CSpotEvent event = {
|
||||
.eventType = eventType,
|
||||
.data = data,
|
||||
.data = data,
|
||||
};
|
||||
|
||||
eventHandler(event);
|
||||
@@ -217,9 +217,9 @@ void SpircController::setEventHandler(cspotEventHandler callback) {
|
||||
info.artist = track.artist;
|
||||
info.imageUrl = track.imageUrl;
|
||||
info.name = track.name;
|
||||
info.duration = track.duration;
|
||||
info.duration = track.duration;
|
||||
|
||||
this->sendEvent(CSpotEventType::TRACK_INFO, info);
|
||||
this->sendEvent(CSpotEventType::TRACK_INFO, info);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ void SpotifyTrack::trackInformationCallback(std::unique_ptr<MercuryResponse> res
|
||||
trackInfo = decodePb<Track>(response->parts[0]);
|
||||
|
||||
CSPOT_LOG(info, "Track name: %s", trackInfo.name.value().c_str());
|
||||
CSPOT_LOG(info, "Track duration: %d", trackInfo.duration.value());
|
||||
|
||||
CSPOT_LOG(debug, "trackInfo.restriction.size() = %d", trackInfo.restriction.size());
|
||||
int altIndex = 0;
|
||||
|
||||
Reference in New Issue
Block a user