1

嗨,我正在尝试在移动客户端上播放来自我宁静的 wcf 服务的视频。当我打开链接时,它不会在 mediaPlayer 和浏览器中播放视频,实际上是开始下载文件。

这是c#代码

public Stream playVideo(string VideoId)
        {
            HttpContext context = HttpContext.Current;
            if (response[1] != null)
            {
                string video_path = Constants._VideosDirectory + "\\" + response[1] + "\\" + VideoId + ".MOV";
                if (File.Exists(video_path))
                {
                    FileStream stream = new FileStream(video_path, FileMode.Open, FileAccess.Read);

                    FileInfo fileInfo = new FileInfo(video_path);
                    context.Response.ClearContent();
                    context.Response.ClearHeaders();
                    context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                    context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.FullName.Replace(" ", "_"));
                    context.Response.ContentType = ReturnFiletype(fileInfo.Extension.ToLower());
                    WebOperationContext.Current.OutgoingResponse.ContentType = "video/quicktime";
                    return stream;
                }
}
}

这是此服务的 webhttpBinding

<bindings>

     <webHttpBinding>
   <binding transferMode="Streamed"
            maxBufferPoolSize="250000000"
            maxBufferSize="5242880"
            maxReceivedMessageSize="2147483647"
            openTimeout="05:25:00"
            closeTimeout="00:25:00"
            sendTimeout="00:25:00"
            receiveTimeout="0:25:00"
            name="webBinding"
       /></webHttpBinding>
   </bindings>
 <service behaviorConfiguration="RestBehavior" name="Test.StreamVideo">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="webBinding"
           contract="Test.IStreamVideo" />
      </service>
4

1 回答 1

1

将代码更改为此解决了我的问题:)

FileStream stream = new FileStream(video_path, FileMode.Open, FileAccess.Read);

                    WebOperationContext.Current.OutgoingResponse.ContentType = "video/quicktime";
                    return stream;
于 2012-08-20T15:05:53.660 回答