我正在尝试创建一个mp3 streamer,但我失败得很糟糕:-)
我的AudioTrackStreamer中有以下内容
protected override void OnBeginStreaming(AudioTrack track, AudioStreamer streamer)
{
//TODO: Set the SetSource property of streamer to a MSS source
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://api.soundcloud.com/tracks/85085126/stream?consumer_key=db840ada2477a93d5fdbcc96a46b37c1");
req.ContentType = "application/octet-stream";
try
{
req.BeginGetRequestStream((callback) =>
{
HttpWebRequest request = (HttpWebRequest)callback.AsyncState;
Stream stream = request.EndGetRequestStream(callback);
Mp3MediaStreamSource src = new Mp3MediaStreamSource(stream, 1000);
streamer.SetSource(src);
NotifyComplete();
}, req);
}
catch { }它失败了,捕捉到了ProtocolIViolationException的消息:
[Arg_InvalidOperationException]
Arguments:
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.50829.0&File=mscorlib.dll&Key=Arg_InvalidOperationException这个文件的网址是我在谷歌搜索免费音乐时发现的,如果你打开它,你会下载一个mp3文件……所以消息来源应该是合法的?
发布于 2013-07-28 23:27:07
NotifyComplete。BeginGetResponse之前,您应该设置req.AllowReadStreamBuffering = false;,否则您的MP3s将在播放前完全下载。Update - my while()循环看起来像这样:
while( true )
{
if( cancel.IsCancellationRequested )
return;
if( buffer.hasFreeSpace() )
{
int cb = await this.downloadAsync().ConfigureAwait( false );
var buffWaiter = m_bufferAwaiter;
if( 0 == cb )
{
Exception ex = new Exception( "runBackgroundAsync: connection dropped" );;
if( null != buffWaiter )
buffWaiter.Fail( ex );
throw ex;
}
if( null != buffWaiter )
{
// The client is waiting for the data to be pre-buffered
if( buffWaiter.haveBuffer( buffer.cbLength ) )
{
// Sufficient data has been downloaded, so playback is going to resume after this haveBuffer() call.
m_bufferAwaiter = null;
}
}
continue; //< Continuing to while(true) without a single sleep.
}
await TaskEx.Delay( this.tsSleepTimeWhenBufferFull, cancel ).ConfigureAwait( false );
}https://stackoverflow.com/questions/17906957
复制相似问题