0

さまざまな例を読んだ後、私はほとんど望んでいた結果にたどり着きました

コード :

WebView myWebView = (WebView)findViewById(R.id.webview);
String strHTMLTags = "<iframe width=\"100%\" height=\"100%\" src=\"http://www.youtube.com/embed/MwdUyxyRwc8?autoplay=1\" frameborder=\"0\" allowfullscreen=\"1\" mozallowfullscreen=\"1\" webkitallowfullscreen=\"1\"></iframe>";

myWebView.setWebViewClient(new WebViewClient());
myWebView.setWebChromeClient(new WebChromeClient() {});     
myWebView.getSettings().setJavaScriptEnabled(true);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

myWebView.loadData(strHTMLTags, "text/html", "utf-8");

これにより、自動開始の横でコードがうまく機能します。

「loadData」の前にこのコードを追加すると:

webSettings.setUserAgentString("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.36 (KHTML, like Gecko) Chrome/13.0.766.0 Safari/534.36");
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setAllowFileAccess(true);

このコードは autostart で動作しますが、解像度の何かが正しくなく、ビデオが本来のように見えません。

setUserAgentString が正確に何を行い、どうすれば彼を autostart で動作させることができますか。

私は別の方法を試します:

public void onPageFinished(WebView view, String url) {

    int cursorXPos = (int) (view.getX() + view.getWidth()/2);
    int cursorYPos = (int) (view.getX() + view.getHeight()/2);
    int cursorXPos = CENTER_OF_SCREEN_X_POS;
    int cursorYPos = CENTER_OF_SCREEN_Y_POS;
    mInstrumentation.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
            SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN, cursorXPos,
            cursorYPos, 0));

    mInstrumentation.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
            SystemClock.uptimeMillis(),MotionEvent.ACTION_UP, cursorXPos,
            cursorYPos, 0));
}

});

エラーが発生します:

05-05 15:33:52.135: E/AndroidRuntime(1334): FATAL EXCEPTION: main
05-05 15:33:52.135: E/AndroidRuntime(1334): java.lang.RuntimeException: This method can not be called from the main application thread
05-05 15:33:52.135: E/AndroidRuntime(1334):     at android.app.Instrumentation.validateNotAppThread(Instrumentation.java:1555)
05-05 15:33:52.135: E/AndroidRuntime(1334):     at android.app.Instrumentation.sendPointerSync(Instrumentation.java:904)
05-05 15:33:52.135: E/AndroidRuntime(1334):     at com.example.embeded.MainActivity$3.onPageFinished(MainActivity.java:69)
05-05 15:33:52.135: E/AndroidRuntime(1334):     at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:317)
05-05 15:33:52.135: E/AndroidRuntime(1334):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 15:33:52.135: E/AndroidRuntime(1334):     at android.os.Looper.loop(Looper.java:137)
05-05 15:33:52.135: E/AndroidRuntime(1334):     at android.app.ActivityThread.main(ActivityThread.java:4517)
05-05 15:33:52.135: E/AndroidRuntime(1334):     at java.lang.reflect.Method.invokeNative(Native Method)
05-05 15:33:52.135: E/AndroidRuntime(1334):     at java.lang.reflect.Method.invoke(Method.java:511)
05-05 15:33:52.135: E/AndroidRuntime(1334):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
05-05 15:33:52.135: E/AndroidRuntime(1334):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
05-05 15:33:52.135: E/AndroidRuntime(1334):     at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1

0
import android.app.Instrumentation;
...

private Instrumentation mInstrumentation;
....

public void onCreate(...) {

    ...
    mInstrumentation = new Instrumentation();
    ....
}

// When the page is ready.
final int cursorXPos = CENTER_OF_SCREEN_X_POS;
final int cursorYPos = CENTER_OF_SCREEN_Y_POS;
new Thread() {
    public void run() {
        mInstrumentation.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
                            SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN, cursorXPos,
                            cursorYPos, 0));

       mInstrumentation.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
                            SystemClock.uptimeMillis(),MotionEvent.ACTION_UP, cursorXPos,
                            cursorYPos, 0));
}
        }.start();
于 2013-05-05T12:10:24.757 に答える