Click here to Skip to main content
15,740,731 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.
//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:

public long KB(long value)
	return value * 1024;

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

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.
Updated 8-Feb-20 22:57pm
Gerry Schmitz 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?
Gerry Schmitz 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