【问题标题】:Playing video from directories that are not in webroot从不在 webroot 中的目录播放视频
【发布时间】:2017-04-10 14:14:58
【问题描述】:

只要视频文件位于服务器的 webroot 目录中,我就可以将视频文件从 IIS Web 服务器播放到客户端 Web 应用程序。但是,我想从不在 webroot 中的共享目录播放它们。这可能吗?? 调用视频文件的Javascript函数,视频是共享名称:

function loadAnotherVideo() {
var video = document.getElementById("video");
var source = document.getElementById("fileSelector");
var path = "//192.168.0.18/Videos/" + source.value;
alert(path);
video.src = path;
video.load();
video.play();

}

【问题讨论】:

    标签: html iis web


    【解决方案1】:

    你应该可以做这样的事情,只要确保应用程序池对存储文件的文件夹具有读取权限

    File - video.aspx
    
    private void Page_Load(object sender, System.EventArgs e)
    {
        //Set the appropriate ContentType.
        Response.ContentType = "video/mp4";
    
        //Get the physical path to the file.
        string FilePath = "c:\path-to-video\video.mp4";
    
        //Write the file directly to the HTTP content output stream.
        Response.WriteFile(FilePath);
    
        Response.End();
    }
    
    HTML
    
    <video width="320" height="240" controls>
      <source src="video.aspx" type="video/mp4">
      Your browser does not support the video tag.
    </video>
    

    基于评论

    这是一篇展示如何使用 javascript 设置/更改视频源的帖子:

    【讨论】:

    • 如果文件是通过 html 选择控件选择的,这可以用于 onchange 事件吗?通过ajax??
    • @JamesAutry 是的,httprequest 响应可以为您提供视频的路径,然后将其设置为视频的 src 属性,以下是更改视频 src 的方法:stackoverflow.com/questions/5235145/…
    • 是的,这似乎适用于 webroot 目录中的视频,但不适用于用户视频目录中的视频。
    • @JamesAutry 好吧,你需要把这两种技术结合起来,然后它才会起作用
    猜你喜欢
    • 1970-01-01
    • 2022-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 2014-11-27
    • 2014-05-01
    相关资源
    最近更新 更多