public SmoothStreamingMediaPlugin()
        {
#if !WINDOWS_PHONE
            _scheduledAds = new List<ScheduledAd>();
            _chunkDownloadManager = new ChunkDownloadManager(this);
            _chunkDownloadManager.DownloadCompleted += ChunkDownloadManager_ChunkDownloadCompleted;
            _chunkDownloadManager.RetryingDownload += ChunkDownloadManager_RetryingChunkDownload;
            _chunkDownloadManager.DownloadExceededMaximumRetries += ChunkDownloadManager_ChunkDownloadExceededMaximumRetryAttempts;
#endif
            _seekCommand = new SeekCommand();
        }
        private void ChunkDownloadManager_ChunkDownloadCompleted(ChunkDownloadManager downloadManager, MediaTrack track,
                                                                 TimeSpan timestamp, ChunkResult result)
        {
            try
            {
                var dataChunk = track.ParentStream.DataChunks.First(i => i.Timestamp == timestamp);

                if (result.Result == ChunkResult.ChunkResultState.Succeeded)
                {
                    var downloadResult = new StreamDownloadResult
                                             {
                                                 DataChunk = dataChunk,
                                                 Stream = result.ChunkData,
                                                 Type = track.ParentStream.Type
                                             };

                    DownloadStreamDataCompleted.IfNotNull(i => i(this, track, downloadResult));
                }
                else
                {
                    Exception err = result.Error ?? new DownloadStreamDataTimeOutException();

                    DownloadStreamDataFailed.IfNotNull(i => i(this, track, dataChunk, err));
                }
            }
            catch (Exception ex)
            {
                DownloadStreamDataFailed.IfNotNull(i => i(this, track, null, ex));
            }
        }
        private void ChunkDownloadManager_ChunkDownloadExceededMaximumRetryAttempts(ChunkDownloadManager chunkDownloadManager, MediaTrack mediaTrack, TimeSpan chunkTimestamp)
        {
            SendLogEntry(KnownLogEntryTypes.SmoothStreamingMediaElementDownloadExceededMaximumRetryAttempts, LogLevel.Error);

            DownloadStreamDataFailed.IfNotNull(i => i(this, mediaTrack, null, new DownloadStreamDataTimeOutException()));
        }
 private void ChunkDownloadManager_RetryingChunkDownload(ChunkDownloadManager chunkDownloadManager, MediaTrack mediaTrack, TimeSpan chunkTimestamp)
 {
     SendLogEntry(KnownLogEntryTypes.SmoothStreamingMediaElementDownloadRetry);
 }