Demo:
1)MainActivity.java:
package
com.venky.playyoutubevideos;
import
android.app.Activity;
import
android.content.Intent;
import
android.net.Uri;
import
android.os.Bundle;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
public class MainActivity extends Activity {
private String Url = "https://www.youtube.com/watch?v=8xg3vE8Ie_E";
Button btnPlay;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnPlay = (Button) findViewById(R.id.buttonPlay);
btnPlay.setOnClickListener(new
OnClickListener() {
@Override
public void onClick(View
arg0) {
// TODO
Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Url));
startActivity(intent);
}
});
}
}
2)main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<Button
android:id="@+id/buttonPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Play
Video" />
</RelativeLayout>
3)Internet Permission:
<uses-permission android:name="android.permission.INTERNET"/>
4)Download this Project Click Here
No comments:
Post a Comment