mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-11 16:16:42 +02:00
mute group
This commit is contained in:
parent
b4bd77c9a6
commit
35ee0fdd12
6 changed files with 76 additions and 18 deletions
|
@ -25,7 +25,6 @@ import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -100,6 +99,11 @@ public class GroupItem extends LinearLayout implements SeekBar.OnSeekBarChangeLi
|
||||||
llClient.addView(clientItem);
|
llClient.addView(clientItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (group.isMuted())
|
||||||
|
ibMute.setImageResource(R.drawable.ic_mute_icon);
|
||||||
|
else
|
||||||
|
ibMute.setImageResource(R.drawable.ic_speaker_icon);
|
||||||
|
|
||||||
if (clientItems.size() >= 2)
|
if (clientItems.size() >= 2)
|
||||||
llVolume.setVisibility(VISIBLE);
|
llVolume.setVisibility(VISIBLE);
|
||||||
else
|
else
|
||||||
|
@ -200,14 +204,11 @@ public class GroupItem extends LinearLayout implements SeekBar.OnSeekBarChangeLi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
/* TODO: group if (v == ibMute) {
|
if (v == ibMute) {
|
||||||
Volume volume = client.getConfig().getVolume();
|
group.setMuted(!group.isMuted());
|
||||||
volume.setMuted(!volume.isMuted());
|
|
||||||
update();
|
update();
|
||||||
listener.onMute(this, volume.isMuted());
|
listener.onMute(this, group.isMuted());
|
||||||
} else
|
} else if (v == ibSettings) {
|
||||||
*/
|
|
||||||
if (v == ibSettings) {
|
|
||||||
listener.onPropertiesClicked(this);
|
listener.onPropertiesClicked(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,6 +246,8 @@ public class GroupItem extends LinearLayout implements SeekBar.OnSeekBarChangeLi
|
||||||
public interface GroupItemListener {
|
public interface GroupItemListener {
|
||||||
void onGroupVolumeChanged(GroupItem group);
|
void onGroupVolumeChanged(GroupItem group);
|
||||||
|
|
||||||
|
void onMute(GroupItem group, boolean mute);
|
||||||
|
|
||||||
void onVolumeChanged(GroupItem group, ClientItem clientItem, int percent, boolean mute);
|
void onVolumeChanged(GroupItem group, ClientItem clientItem, int percent, boolean mute);
|
||||||
|
|
||||||
void onDeleteClicked(GroupItem group, ClientItem clientItem);
|
void onDeleteClicked(GroupItem group, ClientItem clientItem);
|
||||||
|
|
|
@ -58,7 +58,6 @@ import de.badaix.snapcast.control.json.Client;
|
||||||
import de.badaix.snapcast.control.json.Group;
|
import de.badaix.snapcast.control.json.Group;
|
||||||
import de.badaix.snapcast.control.json.ServerStatus;
|
import de.badaix.snapcast.control.json.ServerStatus;
|
||||||
import de.badaix.snapcast.control.json.Stream;
|
import de.badaix.snapcast.control.json.Stream;
|
||||||
import de.badaix.snapcast.control.json.Volume;
|
|
||||||
import de.badaix.snapcast.utils.NsdHelper;
|
import de.badaix.snapcast.utils.NsdHelper;
|
||||||
import de.badaix.snapcast.utils.Settings;
|
import de.badaix.snapcast.utils.Settings;
|
||||||
import de.badaix.snapcast.utils.Setup;
|
import de.badaix.snapcast.utils.Setup;
|
||||||
|
@ -570,6 +569,11 @@ public class MainActivity extends AppCompatActivity implements GroupItem.GroupIt
|
||||||
remoteControl.setGroupVolume(groupItem.getGroup());
|
remoteControl.setGroupVolume(groupItem.getGroup());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMute(GroupItem groupItem, boolean mute) {
|
||||||
|
remoteControl.setGroupMuted(groupItem.getGroup(), mute);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVolumeChanged(GroupItem groupItem, ClientItem clientItem, int percent, boolean mute) {
|
public void onVolumeChanged(GroupItem groupItem, ClientItem clientItem, int percent, boolean mute) {
|
||||||
remoteControl.setVolume(clientItem.getClient(), percent, mute);
|
remoteControl.setVolume(clientItem.getClient(), percent, mute);
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class RemoteControl implements TcpClient.TcpClientListener {
|
||||||
try {
|
try {
|
||||||
if (message.trim().startsWith("[")) {
|
if (message.trim().startsWith("[")) {
|
||||||
JSONArray jsonArray = new JSONArray(message);
|
JSONArray jsonArray = new JSONArray(message);
|
||||||
for (int i=0; i<jsonArray.length(); ++i) {
|
for (int i = 0; i < jsonArray.length(); ++i) {
|
||||||
JSONObject json = jsonArray.getJSONObject(i);
|
JSONObject json = jsonArray.getJSONObject(i);
|
||||||
processJson(tcpClient, json);
|
processJson(tcpClient, json);
|
||||||
}
|
}
|
||||||
|
@ -269,6 +269,18 @@ public class RemoteControl implements TcpClient.TcpClientListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setGroupMuted(Group group, boolean muted) {
|
||||||
|
try {
|
||||||
|
JSONObject body = new JSONObject();
|
||||||
|
body.put("muted", muted);
|
||||||
|
body.put("group", group.getId());
|
||||||
|
JSONObject request = jsonRequest("Group.SetMuted", body);
|
||||||
|
tcpClient.sendMessage(request.toString());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setGroupVolume(Group group) {
|
public void setGroupVolume(Group group) {
|
||||||
try {
|
try {
|
||||||
JSONArray batch = new JSONArray();
|
JSONArray batch = new JSONArray();
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
||||||
private String name = "";
|
private String name = "";
|
||||||
private String id = "";
|
private String id = "";
|
||||||
private String streamId = "";
|
private String streamId = "";
|
||||||
|
private boolean muted = false;
|
||||||
private ArrayList<Client> clients = new ArrayList<Client>();
|
private ArrayList<Client> clients = new ArrayList<Client>();
|
||||||
|
|
||||||
public Group(JSONObject json) {
|
public Group(JSONObject json) {
|
||||||
|
@ -52,7 +53,7 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
||||||
name = json.getString("name");
|
name = json.getString("name");
|
||||||
id = json.getString("id");
|
id = json.getString("id");
|
||||||
streamId = json.getString("stream");
|
streamId = json.getString("stream");
|
||||||
|
muted = json.optBoolean("muted", false);
|
||||||
JSONArray jClients = json.optJSONArray("clients");
|
JSONArray jClients = json.optJSONArray("clients");
|
||||||
if (jClients != null) {
|
if (jClients != null) {
|
||||||
for (int i = 0; i < jClients.length(); i++)
|
for (int i = 0; i < jClients.length(); i++)
|
||||||
|
@ -71,6 +72,7 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
||||||
json.put("name", name);
|
json.put("name", name);
|
||||||
json.put("id", id);
|
json.put("id", id);
|
||||||
json.put("stream", streamId);
|
json.put("stream", streamId);
|
||||||
|
json.put("muted", muted);
|
||||||
json.put("clients", getJsonClients());
|
json.put("clients", getJsonClients());
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -111,6 +113,13 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
||||||
return clients;
|
return clients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMuted() {
|
||||||
|
return muted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMuted(boolean muted) {
|
||||||
|
this.muted = muted;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean removeClient(String id) {
|
public boolean removeClient(String id) {
|
||||||
if (TextUtils.isEmpty(id))
|
if (TextUtils.isEmpty(id))
|
||||||
|
@ -150,7 +159,7 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
||||||
if (TextUtils.isEmpty(id))
|
if (TextUtils.isEmpty(id))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
for (Client c: clients) {
|
for (Client c : clients) {
|
||||||
if (c == null)
|
if (c == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -176,6 +185,7 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
||||||
|
|
||||||
if (name != null ? !name.equals(group.name) : group.name != null) return false;
|
if (name != null ? !name.equals(group.name) : group.name != null) return false;
|
||||||
if (id != null ? !id.equals(group.id) : group.id != null) return false;
|
if (id != null ? !id.equals(group.id) : group.id != null) return false;
|
||||||
|
if (muted != group.muted) return false;
|
||||||
if (streamId != null ? !streamId.equals(group.streamId) : group.streamId != null)
|
if (streamId != null ? !streamId.equals(group.streamId) : group.streamId != null)
|
||||||
return false;
|
return false;
|
||||||
return clients != null ? clients.equals(group.clients) : group.clients == null;
|
return clients != null ? clients.equals(group.clients) : group.clients == null;
|
||||||
|
@ -187,6 +197,7 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
||||||
int result = name != null ? name.hashCode() : 0;
|
int result = name != null ? name.hashCode() : 0;
|
||||||
result = 31 * result + (id != null ? id.hashCode() : 0);
|
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||||
result = 31 * result + (streamId != null ? streamId.hashCode() : 0);
|
result = 31 * result + (streamId != null ? streamId.hashCode() : 0);
|
||||||
|
result = 31 * result + (muted ? 1 : 0);
|
||||||
result = 31 * result + (clients != null ? clients.hashCode() : 0);
|
result = 31 * result + (clients != null ? clients.hashCode() : 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,7 +257,7 @@ struct ClientInfo
|
||||||
|
|
||||||
struct Group
|
struct Group
|
||||||
{
|
{
|
||||||
Group(const ClientInfoPtr client = nullptr)
|
Group(const ClientInfoPtr client = nullptr) : muted(false)
|
||||||
{
|
{
|
||||||
if (client)
|
if (client)
|
||||||
id = client->id;
|
id = client->id;
|
||||||
|
@ -269,6 +269,7 @@ struct Group
|
||||||
name = trim_copy(jGet<std::string>(j, "name", ""));
|
name = trim_copy(jGet<std::string>(j, "name", ""));
|
||||||
id = trim_copy(jGet<std::string>(j, "id", ""));
|
id = trim_copy(jGet<std::string>(j, "id", ""));
|
||||||
streamId = trim_copy(jGet<std::string>(j, "stream", ""));
|
streamId = trim_copy(jGet<std::string>(j, "stream", ""));
|
||||||
|
muted = jGet<bool>(j, "muted", false);
|
||||||
clients.clear();
|
clients.clear();
|
||||||
if (j.count("clients"))
|
if (j.count("clients"))
|
||||||
{
|
{
|
||||||
|
@ -288,6 +289,7 @@ struct Group
|
||||||
j["name"] = trim_copy(name);
|
j["name"] = trim_copy(name);
|
||||||
j["id"] = trim_copy(id);
|
j["id"] = trim_copy(id);
|
||||||
j["stream"] = trim_copy(streamId);
|
j["stream"] = trim_copy(streamId);
|
||||||
|
j["muted"] = muted;
|
||||||
|
|
||||||
json jClients = json::array();
|
json jClients = json::array();
|
||||||
for (auto client: clients)
|
for (auto client: clients)
|
||||||
|
@ -355,6 +357,7 @@ struct Group
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string streamId;
|
std::string streamId;
|
||||||
|
bool muted;
|
||||||
std::vector<ClientInfoPtr> clients;
|
std::vector<ClientInfoPtr> clients;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,8 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
||||||
msg::ServerSettings serverSettings;
|
msg::ServerSettings serverSettings;
|
||||||
serverSettings.setBufferMs(settings_.bufferMs);
|
serverSettings.setBufferMs(settings_.bufferMs);
|
||||||
serverSettings.setVolume(clientInfo->config.volume.percent);
|
serverSettings.setVolume(clientInfo->config.volume.percent);
|
||||||
serverSettings.setMuted(clientInfo->config.volume.muted);
|
GroupPtr group = Config::instance().getGroupFromClient(clientInfo);
|
||||||
|
serverSettings.setMuted(clientInfo->config.volume.muted || group->muted);
|
||||||
serverSettings.setLatency(clientInfo->config.latency);
|
serverSettings.setLatency(clientInfo->config.latency);
|
||||||
session->send(&serverSettings);
|
session->send(&serverSettings);
|
||||||
}
|
}
|
||||||
|
@ -174,6 +175,30 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
||||||
{
|
{
|
||||||
result = group->toJson();
|
result = group->toJson();
|
||||||
}
|
}
|
||||||
|
else if (request->method == "Group.SetMuted")
|
||||||
|
{
|
||||||
|
bool muted = request->params.get<bool>("muted");
|
||||||
|
group->muted = muted;
|
||||||
|
|
||||||
|
/// Update clients
|
||||||
|
for (auto client: group->clients)
|
||||||
|
{
|
||||||
|
session_ptr session = getStreamSession(client->id);
|
||||||
|
if (session != nullptr)
|
||||||
|
{
|
||||||
|
msg::ServerSettings serverSettings;
|
||||||
|
serverSettings.setBufferMs(settings_.bufferMs);
|
||||||
|
serverSettings.setVolume(client->config.volume.percent);
|
||||||
|
GroupPtr group = Config::instance().getGroupFromClient(client);
|
||||||
|
serverSettings.setMuted(client->config.volume.muted || group->muted);
|
||||||
|
serverSettings.setLatency(client->config.latency);
|
||||||
|
session->send(&serverSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Notify others
|
||||||
|
notification.reset(new jsonrpcpp::Notification("Group.OnUpdate", group->toJson()));;
|
||||||
|
}
|
||||||
else if (request->method == "Group.SetStream")
|
else if (request->method == "Group.SetStream")
|
||||||
{
|
{
|
||||||
string streamId = request->params.get("id");
|
string streamId = request->params.get("id");
|
||||||
|
@ -304,7 +329,7 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
||||||
|
|
||||||
void StreamServer::onMessageReceived(ControlSession* controlSession, const std::string& message)
|
void StreamServer::onMessageReceived(ControlSession* controlSession, const std::string& message)
|
||||||
{
|
{
|
||||||
logO << "onMessageReceived: " << message << "\n";
|
logD << "onMessageReceived: " << message << "\n";
|
||||||
jsonrpcpp::entity_ptr entity(nullptr);
|
jsonrpcpp::entity_ptr entity(nullptr);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -328,7 +353,7 @@ void StreamServer::onMessageReceived(ControlSession* controlSession, const std::
|
||||||
if (entity->is_request())
|
if (entity->is_request())
|
||||||
{
|
{
|
||||||
jsonrpcpp::request_ptr request = dynamic_pointer_cast<jsonrpcpp::Request>(entity);
|
jsonrpcpp::request_ptr request = dynamic_pointer_cast<jsonrpcpp::Request>(entity);
|
||||||
logO << "isRequest: " << request->to_json().dump() << "\n";
|
logD << "isRequest: " << request->to_json().dump() << "\n";
|
||||||
ProcessRequest(request, response, notification);
|
ProcessRequest(request, response, notification);
|
||||||
if (response)
|
if (response)
|
||||||
controlSession->send(response->to_json().dump());
|
controlSession->send(response->to_json().dump());
|
||||||
|
@ -338,7 +363,7 @@ void StreamServer::onMessageReceived(ControlSession* controlSession, const std::
|
||||||
else if (entity->is_batch())
|
else if (entity->is_batch())
|
||||||
{
|
{
|
||||||
jsonrpcpp::batch_ptr batch = dynamic_pointer_cast<jsonrpcpp::Batch>(entity);
|
jsonrpcpp::batch_ptr batch = dynamic_pointer_cast<jsonrpcpp::Batch>(entity);
|
||||||
logO << "isBatch: " << batch->to_json().dump() << "\n";
|
logD << "isBatch: " << batch->to_json().dump() << "\n";
|
||||||
jsonrpcpp::Batch responseBatch;
|
jsonrpcpp::Batch responseBatch;
|
||||||
jsonrpcpp::Batch notificationBatch;
|
jsonrpcpp::Batch notificationBatch;
|
||||||
for (const auto& batch_entity: batch->entities)
|
for (const auto& batch_entity: batch->entities)
|
||||||
|
@ -406,7 +431,7 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
||||||
logD << "request kServerSettings\n";
|
logD << "request kServerSettings\n";
|
||||||
msg::ServerSettings* serverSettings = new msg::ServerSettings();
|
msg::ServerSettings* serverSettings = new msg::ServerSettings();
|
||||||
serverSettings->setVolume(client->config.volume.percent);
|
serverSettings->setVolume(client->config.volume.percent);
|
||||||
serverSettings->setMuted(client->config.volume.muted);
|
serverSettings->setMuted(client->config.volume.muted || group->muted);
|
||||||
serverSettings->setLatency(client->config.latency);
|
serverSettings->setLatency(client->config.latency);
|
||||||
serverSettings->setBufferMs(settings_.bufferMs);
|
serverSettings->setBufferMs(settings_.bufferMs);
|
||||||
serverSettings->refersTo = helloMsg.id;
|
serverSettings->refersTo = helloMsg.id;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue