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.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -100,6 +99,11 @@ public class GroupItem extends LinearLayout implements SeekBar.OnSeekBarChangeLi
|
|||
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)
|
||||
llVolume.setVisibility(VISIBLE);
|
||||
else
|
||||
|
@ -200,14 +204,11 @@ public class GroupItem extends LinearLayout implements SeekBar.OnSeekBarChangeLi
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
/* TODO: group if (v == ibMute) {
|
||||
Volume volume = client.getConfig().getVolume();
|
||||
volume.setMuted(!volume.isMuted());
|
||||
if (v == ibMute) {
|
||||
group.setMuted(!group.isMuted());
|
||||
update();
|
||||
listener.onMute(this, volume.isMuted());
|
||||
} else
|
||||
*/
|
||||
if (v == ibSettings) {
|
||||
listener.onMute(this, group.isMuted());
|
||||
} else if (v == ibSettings) {
|
||||
listener.onPropertiesClicked(this);
|
||||
}
|
||||
}
|
||||
|
@ -245,6 +246,8 @@ public class GroupItem extends LinearLayout implements SeekBar.OnSeekBarChangeLi
|
|||
public interface GroupItemListener {
|
||||
void onGroupVolumeChanged(GroupItem group);
|
||||
|
||||
void onMute(GroupItem group, boolean mute);
|
||||
|
||||
void onVolumeChanged(GroupItem group, ClientItem clientItem, int percent, boolean mute);
|
||||
|
||||
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.ServerStatus;
|
||||
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.Settings;
|
||||
import de.badaix.snapcast.utils.Setup;
|
||||
|
@ -570,6 +569,11 @@ public class MainActivity extends AppCompatActivity implements GroupItem.GroupIt
|
|||
remoteControl.setGroupVolume(groupItem.getGroup());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMute(GroupItem groupItem, boolean mute) {
|
||||
remoteControl.setGroupMuted(groupItem.getGroup(), mute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVolumeChanged(GroupItem groupItem, ClientItem clientItem, int percent, boolean mute) {
|
||||
remoteControl.setVolume(clientItem.getClient(), percent, mute);
|
||||
|
|
|
@ -94,7 +94,7 @@ public class RemoteControl implements TcpClient.TcpClientListener {
|
|||
try {
|
||||
if (message.trim().startsWith("[")) {
|
||||
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);
|
||||
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) {
|
||||
try {
|
||||
JSONArray batch = new JSONArray();
|
||||
|
|
|
@ -36,6 +36,7 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
|||
private String name = "";
|
||||
private String id = "";
|
||||
private String streamId = "";
|
||||
private boolean muted = false;
|
||||
private ArrayList<Client> clients = new ArrayList<Client>();
|
||||
|
||||
public Group(JSONObject json) {
|
||||
|
@ -52,7 +53,7 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
|||
name = json.getString("name");
|
||||
id = json.getString("id");
|
||||
streamId = json.getString("stream");
|
||||
|
||||
muted = json.optBoolean("muted", false);
|
||||
JSONArray jClients = json.optJSONArray("clients");
|
||||
if (jClients != null) {
|
||||
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("id", id);
|
||||
json.put("stream", streamId);
|
||||
json.put("muted", muted);
|
||||
json.put("clients", getJsonClients());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -111,6 +113,13 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
|||
return clients;
|
||||
}
|
||||
|
||||
public boolean isMuted() {
|
||||
return muted;
|
||||
}
|
||||
|
||||
public void setMuted(boolean muted) {
|
||||
this.muted = muted;
|
||||
}
|
||||
|
||||
public boolean removeClient(String id) {
|
||||
if (TextUtils.isEmpty(id))
|
||||
|
@ -150,7 +159,7 @@ public class Group implements JsonSerialisable, Comparable<Group> {
|
|||
if (TextUtils.isEmpty(id))
|
||||
return null;
|
||||
|
||||
for (Client c: clients) {
|
||||
for (Client c : clients) {
|
||||
if (c == null)
|
||||
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 (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)
|
||||
return false;
|
||||
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;
|
||||
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||
result = 31 * result + (streamId != null ? streamId.hashCode() : 0);
|
||||
result = 31 * result + (muted ? 1 : 0);
|
||||
result = 31 * result + (clients != null ? clients.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ struct ClientInfo
|
|||
|
||||
struct Group
|
||||
{
|
||||
Group(const ClientInfoPtr client = nullptr)
|
||||
Group(const ClientInfoPtr client = nullptr) : muted(false)
|
||||
{
|
||||
if (client)
|
||||
id = client->id;
|
||||
|
@ -269,6 +269,7 @@ struct Group
|
|||
name = trim_copy(jGet<std::string>(j, "name", ""));
|
||||
id = trim_copy(jGet<std::string>(j, "id", ""));
|
||||
streamId = trim_copy(jGet<std::string>(j, "stream", ""));
|
||||
muted = jGet<bool>(j, "muted", false);
|
||||
clients.clear();
|
||||
if (j.count("clients"))
|
||||
{
|
||||
|
@ -288,6 +289,7 @@ struct Group
|
|||
j["name"] = trim_copy(name);
|
||||
j["id"] = trim_copy(id);
|
||||
j["stream"] = trim_copy(streamId);
|
||||
j["muted"] = muted;
|
||||
|
||||
json jClients = json::array();
|
||||
for (auto client: clients)
|
||||
|
@ -355,6 +357,7 @@ struct Group
|
|||
std::string name;
|
||||
std::string id;
|
||||
std::string streamId;
|
||||
bool muted;
|
||||
std::vector<ClientInfoPtr> clients;
|
||||
};
|
||||
|
||||
|
|
|
@ -155,7 +155,8 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
msg::ServerSettings serverSettings;
|
||||
serverSettings.setBufferMs(settings_.bufferMs);
|
||||
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);
|
||||
session->send(&serverSettings);
|
||||
}
|
||||
|
@ -174,6 +175,30 @@ void StreamServer::ProcessRequest(const jsonrpcpp::request_ptr request, jsonrpcp
|
|||
{
|
||||
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")
|
||||
{
|
||||
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)
|
||||
{
|
||||
logO << "onMessageReceived: " << message << "\n";
|
||||
logD << "onMessageReceived: " << message << "\n";
|
||||
jsonrpcpp::entity_ptr entity(nullptr);
|
||||
try
|
||||
{
|
||||
|
@ -328,7 +353,7 @@ void StreamServer::onMessageReceived(ControlSession* controlSession, const std::
|
|||
if (entity->is_request())
|
||||
{
|
||||
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);
|
||||
if (response)
|
||||
controlSession->send(response->to_json().dump());
|
||||
|
@ -338,7 +363,7 @@ void StreamServer::onMessageReceived(ControlSession* controlSession, const std::
|
|||
else if (entity->is_batch())
|
||||
{
|
||||
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 notificationBatch;
|
||||
for (const auto& batch_entity: batch->entities)
|
||||
|
@ -406,7 +431,7 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
|||
logD << "request kServerSettings\n";
|
||||
msg::ServerSettings* serverSettings = new msg::ServerSettings();
|
||||
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->setBufferMs(settings_.bufferMs);
|
||||
serverSettings->refersTo = helloMsg.id;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue