2017-04-08 46 views
0

只要它們位於服務器上的webroot目錄中,我就可以將視頻文件從IIS Web服務器播放到客戶端Web應用程序。但是,我想從不在webroot中的共享目錄播放它們。這可能嗎?? JavaScript函數調用的視頻文件,視頻是共享名:從不在webroot中的目錄播放視頻

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(); 

}

回答

0

你應該能夠做這樣的事情,只要確保應用程序池已在文件夾上讀取權限所在的文件存儲

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更改視頻源後:

+0

如果文件是通過html選擇控件選擇的,可以使用這個文件onchange事件?通過ajax? –

+0

@JamesAutry是的,httprequest響應可以爲您提供視頻路徑,然後將其設置爲視頻的src屬性,以下是如何更改視頻src:http://stackoverflow.com/questions/5235145/changing- source-on-html5-video-tag – LGSon

+0

是的,這似乎與webroot目錄中的視頻一起使用,但不適用於用戶視頻目錄中的視頻。 –