Click here to Skip to main content
15,867,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Instead of download the whole uploaded audio content from Google Drive (extension can be m4a) I would like to play as buffered content (eg on YouTube, Spotify, etc).

I use drive rest api to download a chunk.
C#
//Maybe I should return MemoryStream
public Stream GetStreamChunk(string fileId, RangeHeaderValue range)
{
	var getrequest = driveService.Files.Get(fileId);
	var stream = new MemoryStream();
	getrequest.DownloadRange(stream, range);
	return stream;
}


What I have tried:

C#
public long KB(long value)
{
	return value * 1024;
}

First of all, I would like to play just a chunk.
C#
long from = 0;
long to = KB(500);
RangeHeaderValue range = new RangeHeaderValue(from, to);
Stream stream = GetStreamChunk(file.Id, range);
using (WaveStream aacStream =
 new BlockAlignReductionStream(
  WaveFormatConversionStream.CreatePcmStream(
   new StreamMediaFoundationReader(stream))))
   {
    using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
     {
	  //aacStream.CurrentTime = new TimeSpan(0, 0, 0);
      waveOut.Init(aacStream);
      waveOut.Play();
     }
   }


Unfortunately, I get an "System.Runtime.InteropServices.COMException" exception at call Play():
In case, if it's a Stream: The byte stream type of the given URL is unsupported. (Exception from HRESULT: 0xC00D36C4)
In case, if it's a MemoryStream: Operation is not allowed for the current position.
Posted
Updated 8-Feb-20 22:57pm
v3
Comments
[no name] 10-Feb-20 11:05am    
A "chunk" is not "valid" audio file; only if you "split" it. And "chunking" is overkill for an audio file. The Media Element is used to control play back.
Deltahun 10-Feb-20 14:42pm    
Thank you! The uploaded contents could be large files. Is there any way to download range as a splitted stream?
[no name] 10-Feb-20 15:45pm    
Most commercial sites "now" get you to select "segments" (time spans) from the selected content. The content is split on the server, and the requested "segment" is downloaded.
Deltahun 11-Feb-20 15:51pm    
Is there any way to do this method using google drive api? Is it possible only with own api?
In the other hand I can't play stream in wpf using "Media Element" without SilverLight.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900