2017-09-12 3 views
19

YouTubeは最近、www.youtube.com/v/{key}の形式で埋め込まれた動画のサポートを停止しました。だから私はビデオを "/ v /"から "/ embed /"に変換しようとしていました。私はビデオに移動しようとすると、ただし、次のエラーは、ポップアップ表示:ウェブブラウザにYouTube動画を埋め込む。オブジェクトがプロパティまたはメソッドをサポートしていません

WPF:

enter image description here

enter image description here

enter image description here

は、私は、以下のものを使用してWebページに移動しています

<WebBrowser x:Name="trailer" Margin="655,308,30,135"/> 

C#の

trailer.Navigate("https://www.youtube.com/embed/v2fDTOdWuQQ?rel=0&amp;showinfo=0"); 

なぜこれが "/埋め込み/" に "/ V /" から切り替えることにより、簡単に作業することができませんか?そしてこの問題を解決するにはどうしたらいいですか?

+2

ちょうどあなたが移動する前に、その呼び出し:https://stackoverflow.com/a/34267121/403671 –

+0

@SimonMourier私は正確を持っています同じ問題があり、あなたのリンク上のRooiWillieの答えが私の状況に適しているようです。 –

+0

@JohnOdomこのスレッドではこれが最高の答えですが、ちょっと、500ドルの価値はありません:-) –

答えて

12

これは、既存のSOスレッド

Use latest version of Internet Explorer in the webbrowser control

スレッドの重複それに行くために実際のコードを持つことで回答がたくさんあります。

同じで最高の提案は、私はバージョンを来て、最新バージョンを使用して、多くの中で作業すると仮定しても安全である、20000に設定HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

でごapp.exeのための非常に高い数値を設定することですなど。この場合は、exeの設定時に簡単に実行できます。どのバージョンが存在し、どのバージョンが存在しないかを心配する必要はありません。埋め込みのために必要な最小限のバージョンはIE 9です。

また、埋め込まれたIEを実際に使用しないこともできます。代わりにChromiumを使用してください。このプロジェクトは、あなたのWinFormsやWPFアプリのクロムブラウザを埋め込むことができます

https://cefsharp.github.io/

で同じのためのCefSharpプロジェクトがあります。アプリはかなりシンプルです

using System.Windows.Forms; 
using CefSharp; 
using CefSharp.WinForms; 

namespace WindowsFormsApp2 
{ 
    public partial class Form1 : Form 
    { 
     ChromiumWebBrowser chrome; 

     private void InitChrome() 
     { 
      CefSettings settings = new CefSettings(); 
      Cef.Initialize(settings); 
      chrome = new ChromiumWebBrowser("https://www.youtube.com/embed/v2fDTOdWuQQ?rel=0&amp;showinfo=0"); 
      this.Controls.Add(chrome); 
      chrome.Dock = DockStyle.Fill; 
     } 
     public Form1() 
     { 
      InitializeComponent(); 
      InitChrome(); 
      //this.webBrowser1.Navigate("https://www.youtube.com/embed/v2fDTOdWuQQ?rel=0&amp;showinfo=0"); 
     } 

    } 
} 

そして素晴らしいです。これは、あなたのアプリがターゲットマシンにインストールされているブラウザに依存しないようにします。

Youtube Chromium

0

WebBrowserを「サイレントモード」に設定してください(これらのスクリプトエラーは無視されます)。 これは、いくつかの黒いIE/COM魔法を必要としますが、機能します。

詳しくは、https://stackoverflow.com/a/6198700/3629903を参照してください。

+1

サイレントモードはエラーを無視し、ブラックボックスを残します。 – difurious

0

使用WebBrowser.NavigateToString代わりのWebBrowser.Navigateとは、URLの代わりにHTMLを使用しています。あなたの容易な参照

enter image description here

+0

以下のリンクからフルワーキングコードをダウンロードできます https://www.dropbox.com/s/peuep22qqy200ot/YoutubeIssue.zip?dl=0 –

1

WPFのために、このスクリーンショットをチェックし この種の問題を解決するための機能「ブラウザエミュレーション」を持っています。

は以下enumaration

public enum BrowserEmulationVersion 
{ 
    Default = 0, 
    Version7 = 7000, 
    Version8 = 8000, 
    Version8Standards = 8888, 
    Version9 = 9000, 
    Version9Standards = 9999, 
    Version10 = 10000, 
    Version10Standards = 10001, 
    Version11 = 11000, 
    Version11Edge = 11001 
} 

新しいクラスを作成する「InternetExplorerBrowserEmulation」を追加し、その中に以下のコードを追加します。

public class InternetExplorerBrowserEmulation 
{ 
    private const string InternetExplorerRootKey = @"Software\Microsoft\Internet Explorer"; 
    private const string BrowserEmulationKey = InternetExplorerRootKey + @"\Main\FeatureControl\FEATURE_BROWSER_EMULATION"; 


    public static int GetInternetExplorerMajorVersion() 
    { 
     int result; 

     result = 0; 

     try 
     { 
      RegistryKey key; 

      key = Registry.LocalMachine.OpenSubKey(InternetExplorerRootKey); 

      if (key != null) 
      { 
       object value; 

       value = key.GetValue("svcVersion", null) ?? key.GetValue("Version", null); 

       if (value != null) 
       { 
        string version; 
        int separator; 

        version = value.ToString(); 
        separator = version.IndexOf('.'); 
        if (separator != -1) 
        { 
         int.TryParse(version.Substring(0, separator), out result); 
        } 
       } 
      } 
     } 
     catch (SecurityException) 
     { 
      // The user does not have the permissions required to read from the registry key. 
     } 
     catch (UnauthorizedAccessException) 
     { 
      // The user does not have the necessary registry rights. 
     } 

     return result; 
    } 

    public static bool SetBrowserEmulationVersion(BrowserEmulationVersion browserEmulationVersion) 
    { 
     bool result; 

     result = false; 

     try 
     { 
      RegistryKey key; 

      key = Registry.CurrentUser.OpenSubKey(BrowserEmulationKey, true); 

      if (key != null) 
      { 
       string programName; 

       programName = Path.GetFileName(Environment.GetCommandLineArgs()[0]); 

       if (browserEmulationVersion != BrowserEmulationVersion.Default) 
       { 
        // if it's a valid value, update or create the value 
        key.SetValue(programName, (int)browserEmulationVersion, RegistryValueKind.DWord); 
       } 
       else 
       { 
        // otherwise, remove the existing value 
        key.DeleteValue(programName, false); 
       } 

       result = true; 
      } 
     } 
     catch (SecurityException) 
     { 
      // The user does not have the permissions required to read from the registry key. 
     } 
     catch (UnauthorizedAccessException) 
     { 
      // The user does not have the necessary registry rights. 
     } 

     return result; 
    } 

    public static bool SetBrowserEmulationVersion() 
    { 
     int ieVersion; 
     BrowserEmulationVersion emulationCode; 

     ieVersion = GetInternetExplorerMajorVersion(); 

     if (ieVersion >= 11) 
     { 
      emulationCode = BrowserEmulationVersion.Version11; 
     } 
     else 
     { 
      switch (ieVersion) 
      { 
       case 10: 
        emulationCode = BrowserEmulationVersion.Version10; 
        break; 
       case 9: 
        emulationCode = BrowserEmulationVersion.Version9; 
        break; 
       case 8: 
        emulationCode = BrowserEmulationVersion.Version8; 
        break; 
       default: 
        emulationCode = BrowserEmulationVersion.Version7; 
        break; 
      } 
     } 

     return SetBrowserEmulationVersion(emulationCode); 
    } 

    public static BrowserEmulationVersion GetBrowserEmulationVersion() 
    { 
     BrowserEmulationVersion result; 

     result = BrowserEmulationVersion.Default; 

     try 
     { 
      RegistryKey key; 

      key = Registry.CurrentUser.OpenSubKey(BrowserEmulationKey, true); 
      if (key != null) 
      { 
       string programName; 
       object value; 

       programName = Path.GetFileName(Environment.GetCommandLineArgs()[0]); 
       value = key.GetValue(programName, null); 

       if (value != null) 
       { 
        result = (BrowserEmulationVersion)Convert.ToInt32(value); 
       } 
      } 
     } 
     catch (SecurityException) 
     { 
      // The user does not have the permissions required to read from the registry key. 
     } 
     catch (UnauthorizedAccessException) 
     { 
      // The user does not have the necessary registry rights. 
     } 

     return result; 
    } 


    public static bool IsBrowserEmulationSet() 
    { 
     return GetBrowserEmulationVersion() != BrowserEmulationVersion.Default; 
    } 
} 

URLを設定する前に、次のコードを追加する必要があります。

if (!InternetExplorerBrowserEmulation.IsBrowserEmulationSet()) 
{ 
    InternetExplorerBrowserEmulation.SetBrowserEmulationVersion(); 
} 

これは、WPFでWebBrowserコントロールを使用して、あなたチューブ・ビデオを実行します

関連する問題