Search code examples
androidwebviewandroid-cardviewandroid-youtube-api

How to set preloaded video pic in cardview and onclicklistener to it?


I have successfully loaded the video in the webview and it is playing also but i want to pass that link to other Activity which will play video using androidYouTubePlayer and also i want to display that webview like below.

problem:

  1. how to display that video like below
  2. how to set OnclickListner for it to pass the link to other activity.

<android.support.v7.widget.CardView
                android:id="@+id/cardViewDemo1"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:layout_margin="5dp"
                android:background="#00ff00"
                android:elevation="3dp"
                app:cardCornerRadius="5dp">

                <WebView
                    android:id="@+id/webView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="15dp" />
            </android.support.v7.widget.CardView>

Solution

  • To send your link to a new activity.

    CardView cardView = (CardView) findViewById(R.id.cardViewDemo1);
    
        cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
    
                String linkVideo = "Here, you set this string with link your video ";
    
                Bundle bundle = new Bundle();
                //HERE, YOU SET YOUR LINK VIDEO, INSIDE KEY "myKeyForReciveLinkVideo";
                bundle.putString("myKeyForReciveLinkVideo",linkVideo);
    
                //START YOUR ACTIVITY
                Intent i = new Intent(YourActivity,YourActivityGo.class);
               //Send your bundle containing the string with the url link to the new activity.
                startActivity(i,bundle);
    
            }
        });
    

    To recover the data passed to your activity, within the activity.

        //Retrieve the arguments passed to new activity.
    
        Bundle bundle = new Bundle(getArguments());
    
        //Use the key you previously defined in the bundle to retrieve the url link string.
    
        String urlLink = bundle.getString("myKeyForReciveLinkVideo");
    

    I hope this helps you.