我正在尝试使用webview和youtube iframe api在Android设备上播放YouTube视频。在4.4,5.0和5.1上测试时一切都很好。但是在4.3上测试同样的视频似乎被裁掉了。即视频仅占网络视图区域的70%左右。作为解决方案?!?!
我的代码如下..
JAVA CODE
Properties p = new Properties();
p.put("text.today", "Today");
p.put("text.month", "Month");
p.put("text.year", "Year");
UtilDateModel model = new UtilDateModel();
Calendar today=Calendar.getInstance();
Date todayDate=new Date();
today.setTime(todayDate);
model.setDate(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DATE));
model.setSelected(true);
JDatePanelImpl datePanel =new JDatePanelImpl(model, p);
JDatePickerImpl datePicker = new JDatePickerImpl(datePanel,new DateLabelFormatter());
datePicker.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
// TODO Auto-generated method stub
System.out.println("fcus lost");
}
@Override
public void focusGained(FocusEvent e) {
// TODO Auto-generated method stub
System.out.println("focus gained");
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
//repaint();
displayImage(categoryAttributeObj,imGroupObj);
}
});
}
});
XML
wvVideo = (WebView)findViewById(R.id.wvVideo);
wvVideo.setWebChromeClient(new WebChromeClient());
WebSettings webSettings = wvVideo.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setMediaPlaybackRequiresUserGesture(false);
wvVideo.addJavascriptInterface(new WebAppInterface(this), "Android");
wvVideo.loadUrl("http://test.com/iframeYouTube.html?videoid="+videoURL);
wvVideo.loadUrl("javascript:playVideo();");
HTML
<WebView
android:id="@+id/wvVideo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="#212121"></WebView>