This class extends memory stream to allow waiting state management and position change notify. Using the WaitForMore method, a event will be launched when the needed data has been read. Position Changed event will be launched when more data has been written on the stream: the maximum resolution for this events is 1024 byte; if the position changed for less than 1024 byte the event won't be raised.
Inheritance: System.IO.MemoryStream
Ejemplo n.º 1
0
        /// <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");
        }
Ejemplo n.º 2
0
 /// <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();
     }
 }
Ejemplo n.º 3
0
 /// <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");
 }
Ejemplo n.º 4
0
 /// <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();
     }
 }