C# Class wpf_player.AudioPlayerModel

Class that implements the ViewModel in MVVM pattern. This class contains the logic for playing audio stream using the Peer as point of access for the network.
Inheritance: INotifyPropertyChanged, IDisposable
Mostrar archivo Open project: zencoders/sambatyon Class Usage Examples

Public Methods

Method Description
AudioPlayerModel ( Peer p = null ) : System

Constructor that initializes all commands and the reference to the Peer.

CheckWaitingBuffering ( long newPosition ) : bool

This method check if the new position is beyond the limit of buffered data; in this case the playback is paused and the player will wait for missing data.

Dispose ( ) : void

Disposes the player calling the close method

SetResourceHandler ( object sender, StreamRequestedArgs args ) : void

Callback used when the streaming is requested using the seach list. This method calls the setResource method.

playback_stopped ( object sender, EventArgs args ) : void

Unused callback

Private Methods

Method Description
NotifyPropertyChanged ( String info ) : void

Method called when a property has been changed. This method rises the event PropertyChange.

close ( object args = null ) : void

This method closes all streams and the disposes the player.

convertSizeToChunk ( long size ) : int

Convert a size in byte to a number of chunk.

pause ( object args = null ) : void

This method handle the pause operation. If the player is currently playing the methods calls NAudio player Pause method, if the player is paused then the play method will called, if the player is in the buffering phase at the start of the streaming session the method try to close the buffer phase and start the playing phase.

play ( object args = null ) : void

Method used to start (or restart) the execution of the track. This resets peer stream and wave stream then initializes the NAudio player and calls its Play method

resetWaveStream ( ) : void

Resets playback related streams and channel.

restartStream ( ) : void

This method resets all structure of the player related to the playback operation but does not modify the peer state (this way the peer keep downloading the file).

resumePlay ( object sender, EventArgs args ) : void

This callback handles playback resuming.

setResource ( KademliaResource rsc ) : void

Sets the current handling resource. If the player is handling the same resource then the methods call restartStream otherwise it calls setupLocalStream

setupLocalStream ( KademliaResource rsc, long spos ) : void

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.

stop ( object args = null ) : void

This method handles the stop operation. If the player is not stopped, the NAudio player will be stopped and some structure will be cleaned

timeFromPosition ( long p ) : double

Converts a position in the buffer to a time instant withing the range of the song lenght

wc_Sample ( object sender, NAudio.Wave.SampleEventArgs e ) : void

This callback is called everytime a sample is player. This method handles current time and current position updates, the stop of the playing at the end of the track and the buffering state.

Method Details

AudioPlayerModel() public method

Constructor that initializes all commands and the reference to the Peer.
public AudioPlayerModel ( Peer p = null ) : System
p PeerLibrary.Peer
return System

CheckWaitingBuffering() public method

This method check if the new position is beyond the limit of buffered data; in this case the playback is paused and the player will wait for missing data.
public CheckWaitingBuffering ( long newPosition ) : bool
newPosition long Position that we want to check
return bool

Dispose() public method

Disposes the player calling the close method
public Dispose ( ) : void
return void

SetResourceHandler() public method

Callback used when the streaming is requested using the seach list. This method calls the setResource method.
public SetResourceHandler ( object sender, StreamRequestedArgs args ) : void
sender object
args StreamRequestedArgs
return void

playback_stopped() public method

Unused callback
public playback_stopped ( object sender, EventArgs args ) : void
sender object
args System.EventArgs
return void