33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
|
using System;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.Threading;
|
||
|
using System.Collections.Generic;
|
||
|
using Aurora.Services;
|
||
|
using Aurora.Proto.Playback;
|
||
|
using Aurora.Proto.General;
|
||
|
using Aurora.Models.Media;
|
||
|
|
||
|
namespace Aurora.RemoteImpl
|
||
|
{
|
||
|
public class RemotePlaybackServiceImpl : RemotePlaybackService.RemotePlaybackServiceBase
|
||
|
{
|
||
|
public override async Task GetSongStream(SongRequest request,
|
||
|
Grpc.Core.IServerStreamWriter<Chunk> responseStream,
|
||
|
Grpc.Core.ServerCallContext context)
|
||
|
{
|
||
|
BaseMedia song = LibraryService.Instance.GetSong(request.Id);
|
||
|
await song.Load();
|
||
|
|
||
|
//Send stream
|
||
|
Console.WriteLine("Begin sending file");
|
||
|
byte[] buffer = new byte[2048]; // read in chunks of 2KB
|
||
|
int bytesRead;
|
||
|
while ((bytesRead = song.DataStream.Read(buffer, 0, buffer.Length)) > 0)
|
||
|
{
|
||
|
Google.Protobuf.ByteString bufferByteString = Google.Protobuf.ByteString.CopyFrom(buffer);
|
||
|
await responseStream.WriteAsync(new Chunk { Content = bufferByteString });
|
||
|
}
|
||
|
Console.WriteLine("Done sending file");
|
||
|
}
|
||
|
}
|
||
|
}
|