Android Processing app playing sequence of Youtube videos

OK. So did you manage to change layout parameters

RelativeLayout.LayoutParams.WRAP_CONTENT)

with height/2 or something?

what is the “layout parameters”?

To have views in Android you need a layout. Imagine it as a transparent window hovering above your sketch. There are different types with different behaviors. When you are going to work with Android you definitely have to study them. The views you create will be attached to that layout.
With the webView, I used a relative layout. You can change the size of these layouts with layout parameters.
When you use WRAP_CONTENT it will use the whole screen, but you can also define it with a number of pixels.

and where does that go in the text?

int s = 0;
int ssa = 0;
int start_time; 
PImage startlogo; 
void setup() { 
  fullScreen(); 
  startlogo = loadImage("logo.png"); 
  startlogo.resize(displayWidth, displayHeight); 
  start_time = millis();
} 
void draw() {
  image(startlogo, 0, 0);
  tint(ssa);
  image(startlogo, 0, 0);
  ssa = (ssa + 15) % 20000; 
  if (millis()-start_time > 5000) { 
    s = 1;
  }
    if (s==1) {
      background(#FF0000);
    }
  }

Just mix it. But then you have to remove the view first. But let’s do it step by step. Did you manage to size the layout?

But I think I got it so that’s an empty window to watch videos on the web right?

the code above is all I’ve got so far😐

More or less. The webView placed on that layout contains the video.

When you merge the webView sketch with yours, you have to make the view invisable first. You can do that in the webView sketch by first adding the imports “import android.view.View;” and also “import.android.CompatUtils;” Then you need a global “int webId” That is to give a signature to the webView, so that it can be recalled. Under the line web.loadUrl you write “webId = CompatUtils.getUniqueViewId();” and then “web.SetVisibility(View.Gone);”
Now your sketch can run.

Down the Errors

import android.webkit.WebViewClient;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView;
import android.view.ViewGroup;
import android.app.Activity;
import android.widget.RelativeLayout;
import android.widget.FrameLayout; 
FrameLayout fl;
Activity act;
WebView web;
WebViewClient wbc;
int s = 0;
int ssa = 0;
int start_time; 
PImage startlogo;


void setup() { 
  fullScreen();
  startlogo = loadImage("logo.png"); 
  startlogo.resize(displayWidth, displayHeight); 
  start_time = millis();
} 
void draw() {
  image(startlogo, 0, 0);
  tint(ssa);
  image(startlogo, 0, 0);
  ssa = (ssa + 15) % 20000; 
  if (millis()-start_time > 5000) { 
    s = 1;
  }
  if (s==1) {
      super.onStart(); 
      act = this.getActivity(); 
      wbc = new WebViewClient(); 
      web = new WebView(act);
      web.setLayoutParams(new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); 
      web.setWebViewClient(wbc); 
      web.getSettings().setJavaScriptEnabled(true); 
      web.loadUrl("http:www.google.com/"); 
      fl = (FrameLayout)act.getWindow().getDecorView().getRootView(); 
      fl.addView(web);

  }
}

java.lang. RuntimeException: WebView cannot be initialized on a thread that has no Looper. at android.webkit.WebView.(WebView.java:421) at android.webkit.WebView.(WebView.java:353)at android.webkit.WebView.(WebView.java:353) at android.webkit.WebView.(WebView.java:336) at android.webkit.WebView.(WebView.java:323)at
android.webkit.WebView.(WebView.java:313)

onStart() and others like onResume(), onPause(), onStop(), and onDestroy(), are Activity Lifecycle functions. See here.
It is important to study them. You can’t place them in draw(). Furthermore the draw() function in itself is a loop that repeats itself around 60 cycles per second, to make animation possible. So try again leaving them outside draw() and add the modifications I mentioned above.

something like that?

import android.webkit.WebViewClient;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView;
import android.view.ViewGroup;
import android.app.Activity;
import android.widget.RelativeLayout;
import android.widget.FrameLayout; 
FrameLayout fl;
Activity act;
WebView web;
WebViewClient wbc;
int s = 0;
int ssa = 0;
int start_time; 
PImage startlogo;


void settings() { 
  fullScreen();
}

public void onStart() { 
  if(s==1){
  super.onStart(); 
  act = this.getActivity(); 
  wbc = new WebViewClient(); 
  web = new WebView(act);
  web.setLayoutParams(new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); 
  web.setWebViewClient(wbc); 
  web.getSettings().setJavaScriptEnabled(true); 
  web.loadUrl("http:www.google.com/"); 
  fl = (FrameLayout)act.getWindow().getDecorView().getRootView(); 
  fl.addView(web);
  }
} 
void setup(){
  startlogo = loadImage("logo.png"); 
  startlogo.resize(displayWidth, displayHeight); 
  start_time = millis();
  
void draw(){
  image(startlogo, 0, 0);
  tint(ssa);
  image(startlogo, 0, 0);
  ssa = (ssa + 15) % 20000; 
  if (millis()-start_time > 5000) { 
    s = 1;
  }
} 

If not, can you show me a video as a test?

And Good morning :slight_smile:

Yes, now when you want to work upon/modify those views, you need a runnable thread like

 act.runOnUiThread(
    new Runnable() {   
    public void run() {  
      web.loadUrl(list[count]);
    }
  }
  );

Try code below and see if you understand what I mean.
The next step is for you to merge the button example on repo with the sketch instead of a mouse sequence. The best thing is to read the other code examples as well to get the idea. I think from here on you can do a lot of things.

// Do not forget the INTERNET permission

import android.webkit.WebViewClient;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView;
import android.view.ViewGroup;
import android.app.Activity;
import android.widget.RelativeLayout;
import android.widget.FrameLayout;
import processing.android.CompatUtils;
import android.view.View;

PImage startlogo; 
FrameLayout fl;
Activity act;
WebView web;
WebViewClient wbc;
int webId, start_time, tnt, count;
boolean just_run_once;
String[] list = {"https://youtu.be/0byZ861sfG4",
                  "https://youtu.be/xQMcsmq9Mq4",
                  "https://youtu.be/1gmhQHT6PHY"
                 };

void setup() { 
  orientation(PORTRAIT);
  background(0, 0, 80);
  startlogo = loadImage("logo.png"); 
  startlogo.resize(displayWidth, displayHeight); 
  start_time = millis();
  just_run_once = true;
  tnt = 255;
  textSize(40);
  textAlign(CENTER);
} 

void settings() {
  fullScreen();
}

void draw() { 
  if (just_run_once) {
    background(0, 0, 80);
    image(startlogo, 0, 0);
    tint(255, tnt);
    tnt -= 5;
    if (millis()-start_time > 3000) { 
      act.runOnUiThread(
        new Runnable() {
        public void run() {
          WebView wv = (WebView)act.findViewById(webId);
          wv.setVisibility(View.VISIBLE);
        }
      }
      );
      just_run_once = false;
      background(0, 0, 80);
      text("Click to load other video", width/2, 2*height/2.5);
    }
  }
}

void mousePressed() {
  count++;  
  act.runOnUiThread(
    new Runnable() {   
    public void run() {  
      web.loadUrl(list[count]);
    }
  }
  );
  if (count == 3) count = 0;
}

void onStop() {
  super.onStop();
  act.finish();
  System.exit(0);
} 

void onPause() {
  super.onPause();
  act.finish ();
  System.exit(0);
} 

void onResume(){
  super.onResume();
}

void onStart() {
  super.onStart();
  act = this.getActivity();
  wbc = new WebViewClient();
  web = new WebView(act);
  web.setLayoutParams(new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, 2*height/3));
  web.setWebViewClient(wbc);
  web.getSettings().setJavaScriptEnabled(true);
  web.loadUrl(list [0]);  
  webId = CompatUtils.getUniqueViewId();
  web.setId(webId);
  web.setVisibility(View.GONE);
  fl = (FrameLayout)act.getWindow().getDecorView().getRootView();
  fl.addView(web);
}

awesome! you are the best I will look at the code and continue to expand!! :smiley:

Can you speak german?

@MonteliaRO ===
i agree with all posts from @Noel who has solved all of your problems (i think!) - Now i think that you have to think mainly to what he has learnt and showed to you:

  • What is a view (knowing that quite all android snippets are views or sub-classes from View)
  • What is a layout and how to create a layout programmatically
  • And more = what is the android lifeCycle and why (for example) you have to create a thread…
    Thanks to @noel , but if you dont try to understand these points, he has lost his time, and you too…
2 Likes