Android Video Embedding
Solution 1:
You should post the stack trace from your exception. And highlight somehow which line it is pointing to. But off the top of my head here is what I notice:
webview = (WebView) findViewById(R.id.webview);
...
tt.addView(webview);
findViewById(id) will return null unless the view is already on the screen. You don't seem to have a WebView in your xml layout (which I assume is the one that is currently on the screen when this code is executing). Since you don't have one in there findViewById will return null to you and on the next line when you try to use a method you'll get a null pointer.
You have a few options basically what it comes down to though is you won't need both findViewById and .addView(), you'll only need one or the other.
You can either:
replace webview = (WebView) findViewById(R.id.webview);
with a WebView constroctor like so: webview = new WebView(this);
Or
you can add a WebView to your xml, leave findViewById how it is now but take out tt.addView(webview);
Also be aware that since you're displaying a youtube page in a webview the user is going to see the whole page, not just a full screen movie. And it is not going to start immediately, they will have to press the start button to get it going. If you are looking for something to just play the video automatically and not show anything else you'll want a VideoView
Here is a fairly straight forward example of VideoView in action You simply have to paste your url into the path variable. Although I am unsure if it knows how to decode a youtube url or not.
Post a Comment for "Android Video Embedding"