我正在尝试编写一个可以将 mp3 文件发送到客户端的 WCF 服务。我需要它来使用渐进式下载传输 mp3 文件,因为客户端是一个 android 应用程序,我希望它尽快开始播放。如何使用 WCF 进行渐进式下载?可能吗?
这是我到目前为止所拥有的。这似乎有效,但不是渐进式下载。它在 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,我的谷歌搜索并没有出现太多。感谢你的帮助。
安卓代码:
player.reset();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(path);
player.prepare();
player.start();
player 是一个MediaPlayer对象。我将数据源设置为路径中的 url。