user.getId(),
collaborative ? 1 : 0
);
/* Create channel callback */
ChannelCallback callback = new ChannelCallback();
/* Create channel and buffer. */
Channel channel = new Channel("Create-Playlist-Channel", Channel.Type.TYPE_PLAYLIST, callback);
byte[] xmlBytes = xml.getBytes();
ByteBuffer buffer = ByteBuffer.allocate(2 + 17 + 4 + 4 + 4 + 1 + 1 + xmlBytes.length);
/* Append channel id, playlist id and some bytes... */
buffer.putShort((short) channel.getId());
buffer.put(requestedPlaylistUUID);
buffer.put((byte) 0x02); // uuid playlist marker?
buffer.putInt(0); // playlist revision?
buffer.putInt(0); // playlist tracks size?
buffer.putInt(-1); // playlist checksum? -1 when create uuid
buffer.put((byte) 0x01); // normally means collaborate, not sure whats with this here
buffer.put((byte) 0x03); // unknown
buffer.put(xmlBytes);
buffer.flip();
/* Register channel. */
Channel.register(channel);
/* Send packet. */
ManagedConnection connection = connectionManager.getManagedConnection();
connection.getProtocol().sendPacket(PacketType.changePlaylist, buffer, "create playlist UUID");
/* Get response. */
byte[] data = callback.getData("create playlist uuid reponse");
connection.close();
xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<playlist>\n" +
new String(data, Charset.forName("UTF-8")) +
"\n</playlist>";