/// <summary> /// Sets all configuration to enable the playback and the downloading of the track from the network. /// After setting all configuration, the player will wait for the buffer to be full enough to start playing. /// </summary> /// <param name="rsc">Resource to Handle</param> /// <param name="spos">Starting position</param> private void setupLocalStream(KademliaResource rsc, long spos) { if (localstream != null) { localstream.Close(); } EnableFlowRestart = true; Dictionary <string, float> tD = new Dictionary <string, float>(); foreach (DhtElement de in rsc.Urls) { Console.WriteLine(de.Url); tD[de.Url.ToString()] = 0; } this.streambuff = new byte[rsc.Tag.FileSize]; localstream = new ObservableStream(streambuff); startPosition = spos; localstream.Seek(spos, SeekOrigin.Begin); pos = spos; NotifyPropertyChanged("Position"); NotifyPropertyChanged("BufferPortion"); localstream.WaitedPositionReached += resumePlay; localstream.PositionChanged += (sender, args) => { NotifyPropertyChanged("BufferPortion"); }; peer.GetFlow(rsc.Tag.FileHash, (int)startPosition, (int)rsc.Tag.FileSize, tD, localstream); BufferingState = true; NotifyPropertyChanged("PlayingState"); startPhaseBuffering = true; localstream.WaitForMore(60000); NotifyPropertyChanged("ResourceTag"); NotifyPropertyChanged("Length"); NotifyPropertyChanged("BigBufferSize"); NotifyPropertyChanged("HasResource"); }
/// <summary> /// This method closes all streams and the disposes the player. /// </summary> /// <param name="args">Unused Params</param> private void close(object args = null) { this.stop(); if (wc != null) { wc.Close(); wc = null; } if (localstream != null) { localstream.Close(); localstream = null; } if (player != null) { player.Dispose(); } }
/// <summary> /// Sets all configuration to enable the playback and the downloading of the track from the network. /// After setting all configuration, the player will wait for the buffer to be full enough to start playing. /// </summary> /// <param name="rsc">Resource to Handle</param> /// <param name="spos">Starting position</param> private void setupLocalStream(KademliaResource rsc,long spos) { if (localstream != null) { localstream.Close(); } EnableFlowRestart = true; Dictionary<string, float> tD = new Dictionary<string, float>(); foreach (DhtElement de in rsc.Urls) { Console.WriteLine(de.Url); tD[de.Url.ToString()] = 0; } this.streambuff = new byte[rsc.Tag.FileSize]; localstream = new ObservableStream(streambuff); startPosition = spos; localstream.Seek(spos, SeekOrigin.Begin); pos = spos; NotifyPropertyChanged("Position"); NotifyPropertyChanged("BufferPortion"); localstream.WaitedPositionReached += resumePlay; localstream.PositionChanged += (sender, args) => { NotifyPropertyChanged("BufferPortion"); }; peer.GetFlow(rsc.Tag.FileHash,(int)startPosition, (int)rsc.Tag.FileSize, tD, localstream); BufferingState = true; NotifyPropertyChanged("PlayingState"); startPhaseBuffering = true; localstream.WaitForMore(60000); NotifyPropertyChanged("ResourceTag"); NotifyPropertyChanged("Length"); NotifyPropertyChanged("BigBufferSize"); NotifyPropertyChanged("HasResource"); }
/// <summary> /// This method closes all streams and the disposes the player. /// </summary> /// <param name="args">Unused Params</param> private void close(object args=null) { this.stop(); if (wc != null) { wc.Close(); wc = null; } if (localstream != null) { localstream.Close(); localstream = null; } if (player != null) { player.Dispose(); } }