How To Play Youtube Onclick Android
Hi guys. today i will post how to play youtube video with button onclick in your project. This code aims to facilitate the application in the usual video featuring her video is placed in the folder raw. how long will make application becomes very large capacity and would be very slow when on the run.
Under the program code will enable the button that will be the key that will read the play youtube video youtube link any already in the input.
Here's the result of the code:
Let's start to make his project:
Create New Project Like this.
Now we design layout for show your video
Code for MainActivity.java
package id.playyoutube;
package id.playyoutube;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button play = (Button) findViewById(R.id.btnplay);
play.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.youtube.com/watch?v=OPf0YbXqDm0")));
Log.i("Video", "Video Playing....");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
}
And run your project. you will look one button to play your youtube video. you can click this button and you will redirect to play youtube. and enjoy it.
Just it. Please Comment me if your not complete your project.
Privacy Publish : SolitEnterprise.










