Karthick M
Karthick M

Reputation: 779

Showing youtube video in webview its displaying the Blank page;while clicking the play button the screen will becomes blank

I am fetching the youtube id from my server and i make as youtube embed url,after that i am showing that youtube url in listview,while click the listitem the youtube video has to be play in webview,that is my requirement,i tried all the ways its not working for me,its displaying the blank page

like this i am fetching from my server and make as youtube url

app1.setUrlWiki("http://www.youtube.com/embed/"+json.getString("youtube_url")+"?fs=0");

this is my mainactivity.java

lv2 =(ListView)findViewById(R.id.listV_main);   
        lv2.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
                Object o = lv2.getItemAtPosition(position);
                Application1 obj_itemDetails = (Application1)o;


                Intent intent1=new Intent(PoojaVideos.this,WebViewActivity.class);
                //Log.d("test","strContactList: "+strContactList);
                //intent1.putExtra("firstKeyName", Uri.parse(((Application1) o).getUrlWiki()));
                String link = Uri.parse(((Application1) o).getUrlWiki()).toString();
                intent1.putExtra("firstKeyName", link);
                startActivity(intent1);


            } 
        });

from there i am sending the url to webview activity according to the click

webviewactivity.java audio alone coming ,but video is not showing

 public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.webview);
             //wv = (WebView) findViewById(R.id.webView);

              mContentView = (FrameLayout) findViewById(R.id.main_content);
             wv = (WebView) findViewById(R.id.webView);
             mCustomViewContainer = (FrameLayout) findViewById(R.id.fullscreen_custom_content);

            wv.getSettings().setJavaScriptEnabled(true);
            wv.getSettings().setPluginsEnabled(true);
            wv.setWebChromeClient(new WebChromeClient() {
            });
            final String mimeType = "text/html";
            final String encoding = "UTF-8";
            String html = getHTML();
            System.out.println(".................."+html);
            wv.loadDataWithBaseURL("", html, mimeType, encoding, "");

        }

        public String getHTML() {

            Intent intent1= getIntent(); // gets the previously created intent
        String firstKeyName1 = intent1.getStringExtra("firstKeyName");
             Toast.makeText(this, firstKeyName1, 1000).show();
             System.out.println("kkkkk."+firstKeyName1);
             String html = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\"  src="firstKeyName1" frameborder=\"0\">\n"
                        + "</iframe>\n";

                return html;

        }

webview.xml

<WebView
    android:id="@+id/webView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

while click the play button,the audio is running,but the video is not showing,it showing black screen.**

**According to the answer i changed my code,now its working fine;i checked in device its working fine but in emulator audio only coming.so guys check in device**

Upvotes: 2

Views: 2718

Answers (2)

Shyam
Shyam

Reputation: 6444

As per doc

In order to support inline HTML5 video in your application, you need to have hardware acceleration turned on, and set a WebChromeClient. For full screen support, implementations of onShowCustomView(View, WebChromeClient.CustomViewCallback) and onHideCustomView() are required, getVideoLoadingProgressView() is optional.

put android:hardwareAccelerated="true" in your AndroidManifest.

Upvotes: 1

Avijit
Avijit

Reputation: 3824

You have to set the url in the html string in this way:

String html = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src='"+firstKeyName1 +"' frameborder=\"0\">\n"
                        + "</iframe>\n";

Now you can easily see the youtube video in that screen.

Upvotes: 1

Related Questions