Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android和xB4上制作嵌入式视频;在API 11下的全屏上打开的Web视图?_Android_Webview_Youtube - Fatal编程技术网

如何在android和xB4上制作嵌入式视频;在API 11下的全屏上打开的Web视图?

如何在android和xB4上制作嵌入式视频;在API 11下的全屏上打开的Web视图?,android,webview,youtube,Android,Webview,Youtube,因此,我的总体情况如下:我必须从wordpress数据库中获取一些HTML,并将其呈现在webview上 所以我不能使用youtube API,我必须呈现这个HTML,我会在上面嵌入视频,我需要它们在全屏上弹出。此解决方案在API 10上不起作用 有没有办法让嵌入的视频在API 11下全屏播放 您可以在WebView上方创建框架布局,并将其附加到VideoView。通过这种方式,您可以管理大小、添加自定义媒体控件,但需要做大量工作,您将面临许多问题 编辑:您可以通过以下方式捕获事件: 如果可以

因此,我的总体情况如下:我必须从wordpress数据库中获取一些HTML,并将其呈现在webview上

所以我不能使用youtube API,我必须呈现这个HTML,我会在上面嵌入视频,我需要它们在全屏上弹出。此解决方案在API 10上不起作用


有没有办法让嵌入的视频在API 11下全屏播放

您可以在WebView上方创建框架布局,并将其附加到VideoView。通过这种方式,您可以管理大小、添加自定义媒体控件,但需要做大量工作,您将面临许多问题

编辑:您可以通过以下方式捕获事件:

  • 如果可以处理html,那么可以添加JS方法,该方法通过JS桥调用应用程序方法。例如,您放置了一个带有
    onclick
    事件的图像。单击此图像可在应用程序()中调用
    JsVideFrameCallbackImpl.playVideo('videoUrl')

    • 或者,您可以通过相同的js桥获取页面上任何html元素的坐标,并将
      VideoView
      放在
      FrameLayout
      上(不要忘记在webview
      wv.getSettings()中启用js。setJavaScriptEnabled(true);在webview中使用javascript之前
      ):

    html中的jsInitMedia(或者您可以在WebView中直接应用此代码作为:
    wv.loadUrl(“javascript:var el=document.getElemen…”)

    JsVideFrameCallbackImpl
    中的java代码中:

        @JavascriptInterface
        public void init(final String json) {
            Log.d(LOG_TAG, "Init:" + json);
            // parse json and extract left, top, width and height
                        // now you can place any View with corresponding coords on your frame
                        //as well you can easy handle all click events  
        }
    

    那么,我如何从网络视图捕获视频播放事件并在视频视图上播放呢?我将在我的回答中为您的问题添加答案,好吗?我将最低API设置为11。您的解决方案不实用,因为我没有编写输出HMTL的代码。更不用说,我必须找到获取图像的方法因为视频和图像本身不足以直观地指示嵌入的视频。>我没有编写输出HMTL的代码。这不是必要的,只是你需要-在html页面上按id或类名查找元素。所有这些。其他的都是从应用程序代码执行的。顺便说一句,这是我的解决方案,适合我的情况继续,但你可以看得更远
    wv.addJavascriptInterface(new JsVideFrameCallbackImpl(), "JsVideFrameCallbackImpl");
    
    //....
    
    private final class JsVideFrameCallbackImpl {
        private final static String LOG_TAG = "JsVideFrameCallbackImpl";
    
        @SuppressWarnings("unused")
        @JavascriptInterface
        public void playVideo(final String videoUri) {
                        // call VideoPlayer activity as example
            startActivity(new Intent(context, VideoPlayer.class));
        }
    }
    
     wv.loadUrl("javascript: jsInitMedia()"); // call js method jsInitMedia
    
        function jsInitMedia() {
            var el = document.getElementById(dataArray[i]); var coords = el.getBoundingClientRect();
            // get top, left coords, width and height with coords.width, el.offsetTop and so on. Send them back as string (i use json format)
            JsVideFrameCallbackImpl.init(jsonDataWithCoordsAsString);
        }
    
        @JavascriptInterface
        public void init(final String json) {
            Log.d(LOG_TAG, "Init:" + json);
            // parse json and extract left, top, width and height
                        // now you can place any View with corresponding coords on your frame
                        //as well you can easy handle all click events  
        }