public ChannelStreamer(Protocol protocol, Media.File file, byte[] key, MusicStream output) { if (key.Length != (128 / 8)) { output.AllAvailable = true; throw new InvalidDataException("Encryption key for channel must be 128-bit."); } _cipher.BlockSize = 128; _cipher.KeySize = 128; _key = key; _cipher.Mode = CipherMode.ECB; //CTR not available _cipher.Padding = PaddingMode.None; _output = output; _file = file; _protocol = protocol; _channelLength = 160 * 1024 * 5 / 8; /* 160 kbit * 5 seconds. */ /* Send first substream request. */ string hash = this._cache.Hash(this._file, this._channelOffset, this._channelLength); if (this._cache != null && this._cache.Contains("substream", hash)) { this._cache.Load("substream", hash, this); } else { try { this._protocol.SendSubstreamRequest(this, this._file, this._channelOffset, this._channelLength); } catch (ProtocolException) { return; } } }
public MusicStream GetMusicStream(Track track, Sharpotify.Media.File file, TimeSpan timeout) { ChannelCallback listener = new ChannelCallback(); ChannelHeaderCallback callback2 = new ChannelHeaderCallback(); try { this.protocol.SendPlayRequest(); } catch (ProtocolException) { return null; } try { this.protocol.SendAesKeyRequest(listener, track, file); } catch (ProtocolException) { return null; } byte[] key = listener.Get(timeout); MusicStream output = new MusicStream(); try { ChannelStreamer streamer = new ChannelStreamer(this.protocol, file, key, output); } catch (Exception) { /* Ignore */ } return output; }