private void UDPMessageReceived(object source, MessegeEventArgs args) { byte[] bytes = args.Messege; string msg = Encoding.UTF8.GetString(bytes, 0, bytes.Length); Debug.WriteLine("UDP Received: {0}", msg); string command = msg.Substring(0, msg.IndexOf(':')); int startIndex = Encoding.UTF8.GetBytes(command + ": ").Length; switch (command) { case "Queue": using (MemoryStream ms = new MemoryStream(bytes, startIndex, bytes.Length - startIndex)) using (BsonReader reader = new BsonReader(ms)) { //reader.ReadRootValueAsArray = true; JsonSerializer serializer = new JsonSerializer(); YoutubeQueued yt = serializer.Deserialize <YoutubeQueued>(reader); if (yt.userId == User.DeviceUser.Id) { return; } Debug.WriteLine("UDP/ Adding to Queue {0}", yt.title); OnUDPQueued(yt); } break; case "Delete": int qPosDelete = int.Parse(msg.Substring(msg.IndexOf(':') + 1)); //to int OnDeletepiece(qPosDelete); break; case "PlayedNow": int qPosPlayedNow = BitConverter.ToInt32(bytes, startIndex); //int qPosPlayedNow = int.Parse(msg.Substring(msg.IndexOf(':') + 1)); OnPlayedNow(qPosPlayedNow); break; default: Debug.WriteLine("UDP/ Cannot interpret right..."); break; } }
protected virtual void OnUDPQueued(YoutubeQueued piece) { MusicPiece mPiece = new MusicPiece(piece); UDPQueued?.Invoke(this, new PiecePosArgs(mPiece, piece.qPos)); }