我使用WebView将vpaid html5player变成app.Webview发生在javascript错误中..
08-01 10:20:06.967: I/chromium(24646): [INFO:CONSOLE(60)] "Uncaught TypeError: this[a] is not a function", source: http://vjs.zencdn.net/4.12/video.js (60)
MainActivity.java
package com.example.gowsample;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.ConsoleMessage;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
public class MainActivity extends Activity {
private WebView mWebview ;
@SuppressWarnings("deprecation")
@SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebview = (WebView)findViewById(R.id.webView1);
WebSettings settings = mWebview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
String summary = "<!DOCTYPE html><html><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"><!-- Video.js 4 -->\n<link href=\"http://vjs.zencdn.net/4.12/video-js.css\" rel=\"stylesheet\">\n<script src=\"http://mysite/VPAID1/video.js\"></script>\n<!-- Common -->\n<link href=\"http://mysite/bin/videojs.vast.vpaid.min.css\" rel=\"stylesheet\">\n<!-- Video.js 5 -->\n<script src=\"http://mysite/bin/videojs_4.vast.vpaid.min.js\"></script>\n<script src=\"http://mysite/bin/es5-shim.js\"></script>\n<script src=\"http://mysite/VPAID/bin/ie8fix.js\"></script>\n<video id=\"example_video_1\" class=\"video-js vjs-default-skin\"\n controls preload=\"auto\" width=\"300\" height=\"250\"\n poster=\"http://vjs.zencdn.net/v/oceans.png\"\n data-setup='{\n \"plugins\": {\n \"vastClient\": {\n \"adTagUrl\": \"http://mysite/sincity.xml\",\n \"adCancelTimeout\": 5000,\n \"adsEnabled\": true\n }\n }\n }'>\n <source src=\"http://vjs.zencdn.net/v/oceans.mp4\" type='video/mp4'/>\n\n \n</video>\n</html>";
String html =summary;
mWebview.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Log.d("Moorthy", consoleMessage.message() + " -- From line "
+ consoleMessage.lineNumber() + " of "
+ consoleMessage.sourceId());
return super.onConsoleMessage(consoleMessage);
}
});
mWebview.loadData(html, "text/html", null);
//mWebview.loadUrl("http://dhmoorthy94.000webhostapp.com/vpaid/VPAID1/secretmedia.php");
}
}
知道可能导致这些错误的原因吗?
注意:mWebview.loadUrl
它的完美工作..但加载数据传递相同的值javascript错误发生...
答案 0 :(得分:-2)
我复制了你的代码并在我的机器上进行了测试..事情很好。当我查看您的HTML数据时,有一个URL需要在WebView上加载Internet。所以我做了什么,我只给了权限,你的代码工作正常,所以