如何实现 IInputStream UWP

How to implement IInputStream UWP

我应该得到一个 IInputStream 来传递给方法:CreateFromStreamAsync,我必须专门使用这个方法,因为我使用了一个 AudioGraph(我传递给这个方法的 uri 是一个收听广播的 uri)

“HLS”我是从下面猜的link

代码class StreamRadio:

 public class StreamRadio : IInputStream
 {
    public IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, uint count, InputStreamOptions options)
    {
        return AsyncInfo.Run<IBuffer, uint>(async (token, progress) =>
        {
            await Task.Delay(2000);
            var output = buffer.AsStream();
            var outputRadio = output.AsInputStream();
            IBuffer bufferRadio = new DataReader(outputRadio).ReadBuffer(64);
            return bufferRadio;
        });
    }

    public void Dispose()
    {
        throw new NotImplementedException();
    }
 }

代码方法:

StreamRadio streamRadio = new StreamRadio();

var adaptiveMediaSourceResult = await AdaptiveMediaSource.CreateFromStreamAsync(streamRadio, new Uri(uriRadio), "HLS");
if (adaptiveMediaSourceResult.Status != AdaptiveMediaSourceCreationStatus.Success)
{
     return null;
}

提前致谢!

解决方案:

 var random = RandomAccessStreamReference.CreateFromUri(new Uri(uriRadio));
 IRandomAccessStream stream = await random.OpenReadAsync();
 var adaptiveMediaSourceResult = await AdaptiveMediaSource.CreateFromStreamAsync(stream, new Uri(uriRadio), "HLS");