Does anyone know how to view a YouTube video or some streaming of video through a WebView
?
In the code below, there are three buttons. The first one takes the user to the link he typed, the second is fixed to go to Google's website and the third is supposed to run the streaming of NasaTV video, but only loads. I also tried putting a YouTube link and it does not run through WebView
.
My code:
public class MainActivity extends ActionBarActivity {
private EditText editText;
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.url);
webView = (WebView) findViewById(R.id.webViewlayout);
webView.setWebViewClient(new MyBrowser());
}
public void abrirPagina (View v){
String url = editText.getText().toString();
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadUrl(url);
}
public void acessoDireto (View v){
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadUrl("http://www.google.com.br");
}
public void nasaTV (View v){
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadUrl("http://www.ustream.tv/nasahdtv");
}
private class MyBrowser extends WebViewClient{
public boolean overrideUrlLoading (WebView view, String url){
view.loadUrl(url);
return true;
}
}
}
My manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.luizhmu.aulas_android_webview" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>