所以,我的整體情況如下:我必須從一個WordPress數據庫中獲取一些HTML並在webview上呈現它。如何在Android 11的API 11下全屏打開嵌入式視頻?
所以我不能使用YouTube API,我必須渲染這個HTML,生病了嵌入了視頻,我需要它們全屏彈出。此解決方案Videos not playing in fullscreen mode將無法在API 10上工作。
是否有任何使嵌入的視頻在API 11下全屏播放?
所以,我的整體情況如下:我必須從一個WordPress數據庫中獲取一些HTML並在webview上呈現它。如何在Android 11的API 11下全屏打開嵌入式視頻?
所以我不能使用YouTube API,我必須渲染這個HTML,生病了嵌入了視頻,我需要它們全屏彈出。此解決方案Videos not playing in fullscreen mode將無法在API 10上工作。
是否有任何使嵌入的視頻在API 11下全屏播放?
您可以在WebView上方創建Frame佈局並將其附加到VideoView。通過這種方式,您可以管理大小,添加自定義MediaControls,但是有很多工作,並且您將面臨許多問題。
編輯:您可以捕捉事件:
如果你能處理HTML,你可以添加JS方法,調用應用程序方法throught JS的橋樑。舉例來說,你把一個圖像與onclick
事件。在您的應用程序點擊此圖片調用JsVideFrameCallbackImpl.playVideo('videoUrl')
(http://android-developers.blogspot.com/2008/09/using-webviews.html):
<img src="img/video_1.jpg" width="494px" height="340px" onclick="javascript: JsVideFrameCallbackImpl.playVideo('videoUrl')">
,並在您的活動連接addJavascriptInterface
到網頁視圖:
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));
}
}
,或者你可以得到任何COORDS html元素通過相同的js橋和地方VideoView
在FrameLayout
(不要忘記啓用js在webview wv.getSettings().setJavaScriptEnabled(true); before using javascript in webview
):
wv.loadUrl("javascript: jsInitMedia()"); // call js method jsInitMedia
jsInitMedia在HTML(或者你可以直接在WebView中應用此代碼:wv.loadUrl("javascript: var el = document.getElemen...")
:
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);
}
,並在Java代碼中JsVideFrameCallbackImpl
:
@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
}
如何我可以捕獲從WebView播放的視頻事件並在VideoView上播放它嗎? –
我要在我的回答中添加對您問題的回答,好嗎? – validcat
我只是將最小的API設置爲11.您的解決方案不實用,因爲我沒有編寫將輸出HMTL的代碼。更不用說,我必須找到一種方法來獲得視頻和圖像本身的圖像不會足夠直觀,以指示嵌入式視頻。 –