Improved streaming. Though now it streams a portion of the song if it is above 4MB. Will look into it.

This commit is contained in:
amazing-username
2019-07-02 17:39:02 -07:00
parent 4de95c1ef6
commit 22b5c7c346
2 changed files with 30 additions and 0 deletions
+25
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
@@ -16,6 +17,30 @@ namespace Mear.Managers
public class SongManager
{
#region Methods
public async Task StreamSong()
{
var url = $"https://www.soaricarus.com/api/v1/song/stream/{Playback.MearPlayer.OnSong.Id}";
var streamReq = (HttpWebRequest)WebRequest.Create(url);
var tokRepo = new DBTokenRepository();
var token = tokRepo.RetrieveToken();
streamReq.Headers.Add(HttpRequestHeader.Authorization, $"Bearer {token.AccessToken}");
streamReq.KeepAlive = true;
streamReq.ContentType = "application/octet-stream";
streamReq.AddRange(0, long.MaxValue);
streamReq.Method = WebRequestMethods.Http.Get;
using (var songStream = ((HttpWebResponse)streamReq.GetResponse()).GetResponseStream())
{
using (var songTemp = new FileStream(Playback.MearPlayer.OnSong.SongPath, FileMode.CreateNew, FileAccess.ReadWrite,
FileShare.Read, bufferSize: 4096, useAsync: true))
{
await songStream.CopyToAsync(songTemp);
await Task.Delay(500);
}
}
}
// Do not use
public bool DownloadStream(ref Song song)
{
try
+5
View File
@@ -276,6 +276,9 @@ namespace Mear.Playback
var songMgr = new SongManager();
_song.SongPath = tmpFile;
songMgr.StreamSong();
/**
var downloaded = songMgr.DownloadStream(ref _song);
@@ -283,7 +286,9 @@ namespace Mear.Playback
{
PlaySong();
}
*/
PlaySong();
return Task.Run(() =>
{
return _song;