0

after reading diffrent examples i allmost rech to the wanted result

the code :

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");

this will make the code works great beside the auto start .

if i add this code before "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);

this code works with autostart but something with the resolution is not right and the video not looking as he should .

what exactly setUserAgentString does and how can i make him work with autostart .

i try another way :

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));
}

});

and get error :

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)
Jesus Dimrix
  • 4,378
  • 4
  • 28
  • 62

1 Answers1

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();
Sagar Waghmare
  • 4,702
  • 1
  • 19
  • 20
  • i added to my question your suggestion and the error that i gut . obviously im doing something wrong – Jesus Dimrix May 05 '13 at 12:37
  • ok , its not crush now . i need to figure out now where the button pressed couse the video still not start . maybe my X,Y not right – Jesus Dimrix May 05 '13 at 13:14