2015-01-21 58 views
2

我想在我的代碼是使用IFrame 的wp8 webbrowser控件中自動播放youtube視頻。如何在wp8中自動播放Youtube視頻webBrowser控件Iframe

string ss = "<!doctype html>" + 
    "<html><head><meta bgcolor=\"black\" name=\"viewport\" content=\"width=1080, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0\" /><title></title></head><body style=background-color:black;>" + 
    "<iframe \"background-color:black\" id=\"ytplayer\" type=\"text/html\" width=\"1080\" height=\"700\" src=\"https://www.youtube.com/embed/?rel=0&autoplay=1&loop=1&modestbranding=1&playlist=" + youtubeIDS + "&playsinline=1&controls=0\" frameborder=\"0\" allowfullscreen>" + 
    "</body></html>"; 

webbrowser.NavigatetoString(ss); 

但無法自動播放視頻。

回答

1

這不是與C#相關的問題,而是HTML。您的YouTube來源鏈接中存在大量雜亂無章的內容。試試這個純粹主義鏈接激活自動播放功能,然後添加其他鏈接屬性,如果需要的話:

string ss = "<!doctype html>" + 
    "<html><head></head><body>" + 
    "<iframe id=\"ytplayer\" type=\"text/html\" width=\"1080\" height=\"700\" src=\"https://www.youtube.com/embed/" + youtubeIDS + "?autoplay=1\">" + 
    "</body></html>"; 
webbrowser.NavigatetoString(ss); 

顯然,rel=0屬性導致問題的一些,因此這個完整版可以正常工作(只是刪除rel=0):

string ss = "<!doctype html>" + 
    "<html><head><meta bgcolor=\"black\" name=\"viewport\" content=\"width=1080, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0\" /><title></title></head><body style=background-color:black;>" + 
    "<iframe \"background-color:black\" id=\"ytplayer\" type=\"text/html\" width=\"1080\" height=\"700\" src=\"https://www.youtube.com/embed/?autoplay=1&loop=1&modestbranding=1&playlist=" + youtubeIDS + "&playsinline=1&controls=0\" frameborder=\"0\" allowfullscreen>" + 
    "</body></html>"; 
webbrowser.NavigatetoString(ss); 

如果一切失敗,嘗試此鏈接,他們討論的一個非常類似的話題:How to make an embedded Youtube video automatically start playing?

UPDATE:如果EV這並不能消除所有可能存在問題的潛在影響, G。在本地創建一個HTML文件並添加最小的HTML命令,然後使用幾個Web瀏覽器打開該文件以檢查YouTube自動播放功能。應該工作的示例:

<html> 
    <head> 
     <title>Minimal YouTube Autoplay Example</title> 
    </head> 
    <body> 
     <iframe width="560" height="315" src="http://www.youtube.com/embed/xV7Ha3VDbzE?autoplay=1" frameborder="0"></iframe> 
    </body> 
</html> 

然後從那裏開始。如果這不起作用,雖然你沒有編程問題來解決;-)

+0

沒有它仍然沒有工作.. – 2015-01-21 05:29:53

+0

哪兩個選項之一?都?你是否已經刪除了'rel = 0'部分,並確保源代碼除了'playlist = 1'之外沒有任何混亂? – 2015-01-21 05:32:09

+0

兩者都無法正常運行我正在Lumia 530 Wp8.1上運行我的應用程序 – 2015-01-21 05:39:20

相關問題