如何在WebView中搜索Youtube视频?

时间:2015-01-10 15:32:38

标签: android webview youtube

我有一个带有两个活动的Android应用程序:其中一个是Youtube Webview,另一个是从键盘获取字符串的mainactivity。

有没有办法在Youtube上显示我开始Webview活动时给出的字符串中的搜索?

由于

1 个答案:

答案 0 :(得分:0)

是的,您可以搜索&在webview中播放视频

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <WebView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/webView"
            android:layout_gravity="center"
            />
    <FrameLayout
            android:id="@+id/customViewContainer"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:visibility="gone"
            />
</LinearLayout>

这是youtube的布局

  <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:id="@+id/progress_indicator"
                  android:orientation="vertical"
                  android:layout_centerInParent="true"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent">

        <ProgressBar android:id="@android:id/progress"
                     style="?android:attr/progressBarStyleLarge"
                     android:layout_gravity="center"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"/>

        <TextView android:paddingTop="5dip"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  android:text="loading"
                  android:textSize="14sp"
                  android:textColor="?android:attr/textColorPrimary"/>
    </LinearLayout>

youtube进度的布局

universalWebViewFragment = UniversalWebViewFragment.newInstance();
getFragmentManager().beginTransaction()
        .add(R.id.frame_root, universalWebViewFragment).commit();

像这样使用

                    universalWebViewFragment.searchOnYoutube(searchView
                            .getText().toString());

像这样搜索视频

 <uses-permission android:name="android.permission.INTERNET" />

别忘了添加权限

org.xml.sax.SAXParseException; systemId: file:/Users/kevin/repo/xsdTest/target/classes/schemas/saml-schema-protocol-2.0.xsd; lineNumber: 32; columnNumber: 56; src-resolve: Cannot resolve the name 'ds:Signature' to a(n) 'element declaration' component.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:4162)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(XSDHandler.java:4145)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getGlobalDecl(XSDHandler.java:1678)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDElementTraverser.traverseLocal(XSDElementTraverser.java:170)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.traverseLocalElements(XSDHandler.java:3618)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:633)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:617)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:575)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:541)
at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:255)
at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:638)
at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:670)
at testXsd.TestSchemaValidation.validateSaml(TestSchemaValidation.java:35)
at testXsd.TestSchemaValidation.main(TestSchemaValidation.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

在此处查找完整项目https://github.com/hiteshsahu/UniversalWebPageLoader