我正在创建一个从媒体服务器流式传输视频的Android应用。我正在使用我的频道的列表视图和控制视频的switch语句。在switch语句中有一些简单的javascript代码,例如:
webView.loadUrl("javascript:void(jwplayer().playlistItem(2))");
这样可以正常但随机地抛出这个错误很多。我无法找到原因,我已经尝试不等待视频加载和加载新视频,有时它会导致它,有时它不会,我只选择了4个视频并在更改前观看了5秒,这个时候导致它,有时不会。我的logcat显示了这个:
03-20 14:19:29.710: D/dalvikvm(14679): GC_CONCURRENT freed 426K, 8% free 7600K/8199K, paused 3ms+3ms
03-20 14:20:32.490: D/dalvikvm(14679): threadid=18: still suspended after undo (sc=1 dc=1)
03-20 14:20:32.540: D/dalvikvm(14679): threadid=18: still suspended after undo (sc=1 dc=1)
03-20 14:20:32.550: D/dalvikvm(14679): GC_CONCURRENT freed 426K, 8% free 7599K/8199K, paused 4ms+3ms
03-20 14:20:37.220: W/System.err(14679): java.net.SocketException: No route to host
03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
03-20 14:20:37.220: W/System.err(14679): at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:369)
03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:208)
03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:431)
03-20 14:20:37.220: W/System.err(14679): at java.net.Socket.connect(Socket.java:901)
03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304)
03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnect ion(HttpURLConnectionImpl.java:292)
03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274)
03-20 14:20:37.220: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:217)
03-20 14:20:37.230: W/System.err(14679): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:624)
03-20 14:20:37.230: W/System.err(14679): at dalvik.system.NativeStart.run(Native Method)
03-20 14:20:37.230: W/System.err(14679): at dalvik.system.NativeStart.run(Native Method)
答案 0 :(得分:0)
您是否在视图上启用了javasctript?
webView.getSettings().setJavaScriptEnabled(true);
另外,你应该考虑在javascript语句的末尾添加一个冒号。
webView.loadUrl("javascript:void(jwplayer().playlistItem(2));");
如果没有任何事情要做,请尝试捕获异常,并尝试一定次数,在web浏览器中有一些不稳定因素和android中的httpclients。