【问题标题】:YouTube video in AndroidAndroid 中的 YouTube 视频
【发布时间】:2011-03-02 02:09:55
【问题描述】:

我正在尝试在 Android 中加载 YouTube 视频。

我在xml中添加了一个WebView:

  <WebView android:id="@+id/VideoView"
           android:layout_height="fill_parent"
           android:layout_width="fill_parent" />

然后我按如下方式加载它:

WebView webview = new WebView(this);
setContentView(R.layout.webview);

String htmlString = "<html> <body> <embed src=\"http://www.youtube.com/watch?v=XS998HaGk9M\"; type=application/x-shockwave-flash width="+640+" height="+385+"> </embed> </body> </html>";   
webview.loadData(htmlString, "text/html", "utf-8");

我已向清单添加了适当的权限。我收到的只是一个空白的白色屏幕,没有任何加载。

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: android youtube


    【解决方案1】:

    不要使用webview,而是开始一个新的Intent...

        startActivity(new Intent(Intent.ACTION_VIEW, 
           Uri.parse("http://www.youtube.com/watch?v=XS998HaGk9M")));
    

    【讨论】:

    • +1 因为这也将允许不支持 Flash 的旧手机使用 YouTube 客户端。
    • 我尝试过使用它,但我得到的网页不可用。此外,我想尝试控制有多少视图将显示 youtube 视频,这就是我使用 webview 的原因。
    • 如果网页不可用,那是你的问题 ;-)
    • 是的,我知道,它说在 log cat url not found 中收到错误。有什么想法吗?
    • +1 为 Ryan Berger。正是我想要的方式,一行代码!
    猜你喜欢
    • 1970-01-01
    • 2013-10-26
    • 2014-02-12
    • 1970-01-01
    • 2020-11-17
    • 1970-01-01
    • 2014-04-28
    • 2011-04-30
    相关资源
    最近更新 更多