我将尝试编写一个WCF服务,用于向客户端发送mp3文件。我需要使用渐进式下载来传输mp3文件,因为客户端是Android应用程序,我希望它能尽快开始播放。如何使用WCF进行渐进式下载?这可能吗?
以下是我目前的代码。这似乎可以工作,但它不是渐进式下载。在Android应用程序中播放时,需要等待整个文件下载完毕。
服务合同:
如果您可以提供有关渐进式下载的来源链接,那将非常有帮助。我的谷歌搜索并没有找到太多关于渐进式下载+WCF的内容。感谢您的帮助。
Android代码:
以下是我目前的代码。这似乎可以工作,但它不是渐进式下载。在Android应用程序中播放时,需要等待整个文件下载完毕。
服务合同:
[OperationContract, WebGet(UriTemplate = "/GetFileStream/?filepath={virtualPath}")]
Stream GetFileStream(string virtualPath);
服务配置:
<bindings>
<webHttpBinding>
<binding name="streamedHttpBinding" transferMode="StreamedResponse"
maxReceivedMessageSize="1000000000">
</binding>
</webHttpBinding>
</bindings>
<service name="...">
<endpoint address="" behaviorConfiguration="restful" binding="webHttpBinding"
bindingConfiguration="streamedHttpBinding"
contract="..." />
</service>
<behaviors>
<endpointBehaviors>
<behavior name="restful">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
如果您可以提供有关渐进式下载的来源链接,那将非常有帮助。我的谷歌搜索并没有找到太多关于渐进式下载+WCF的内容。感谢您的帮助。
Android代码:
player.reset();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(path);
player.prepare();
player.start();
player是一个MediaPlayer对象。我将数据源设置为路径中的url。