public static YandexStreamTrack Open(Uri trackUrl, int?sizeTrack) { var streamTrack = new YandexStreamTrack { Position = 0, TrackSize = sizeTrack, Url = trackUrl }; streamTrack.Task = Task.Factory.StartNew(() => { var response = HttpWebRequest.Create(trackUrl).GetResponse(); using (var stream = response.GetResponseStream()) { byte[] buffer = new byte[sizeTrack ?? 0]; int read; while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) { var pos = streamTrack.Position; streamTrack.Position = streamTrack.Length; streamTrack.Write(buffer, 0, read); streamTrack.Position = pos; } streamTrack.OnComplated(); } }); return(streamTrack); }
public YandexStreamTrack ExtractStreamTrack(YandexTrack track) { var trackDonloadInfo = GetDownloadTrackInfo(track.StorageDir); var trackDownloadUrl = _settings.GetURLDownloadTrack(track, trackDonloadInfo); var isNetworing = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable(); return(YandexStreamTrack.Open(trackDownloadUrl, track.FileSize)); }