How to Create Video Streaming Application in Android
Hello everyone , as per specific demand I am going to share Android Video Streaming Application , it give you basiconcept how you can stream Online video to your Android Application . Later in upcomming post I will explain how to stream youtube Video to your Android Application.
Prerequisites:
- JDK 6.0 or above
- Android Studio
Steps to follow:
- Create a New Android Studio project name VideoStream.
- Select minimum API level 15 so it will run Maximum of Android device that are Active on google Play then click next.
- Select Blank Activity and your Activity name is VideoStreamActivity click next > click finish.
- Inside VideoStreamActivity write the following code;
public class VideoStreamActivity extends Activity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the layout from video_main.xml
setContentView(R.layout.main);
// Locate the button in activity_main.xml
button = (Button) findViewById(R.id.button1);
// Capture button clicks
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Start NewActivity.class
Intent myIntent = new Intent(VideoStreamActivity.this, Show.class);
startActivity(myIntent);
}
});
}
}
5.Now create Show.java Class. Inside Show.java write down the following code.
public class Show extends Activity{
ProgressDialog pd;
VideoView view;
String URL = "http://www.androidbegin.com/tutorial/AndroidCommercial.3gp";
/* (non-Javadoc) * @see android.app.Activity#onCreate(android.os.Bundle)*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
view = (VideoView)findViewById(R.id.videoView1);
pd = new ProgressDialog(Show.this);
pd.setTitle("Video Streamming Demo");
pd.setMessage("Buffering...");
pd.setIndeterminate(false);
pd.setCancelable(false);
pd.show();
try{
MediaController controller = new MediaController(Show.this);
controller.setAnchorView(view);
Uri vid = Uri.parse(URL);
view.setMediaController(controller);
view.setVideoURI(vid);
}catch(Exception e){
Log.e("Error", e.getMessage());
e.printStackTrace();
}
view.requestFocus();
view.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
pd.dismiss();
view.start();
}
});
}
}
ProgressDialog pd;
VideoView view;
String URL = "http://www.androidbegin.com/tutorial/AndroidCommercial.3gp";
/* (non-Javadoc) * @see android.app.Activity#onCreate(android.os.Bundle)*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
view = (VideoView)findViewById(R.id.videoView1);
pd = new ProgressDialog(Show.this);
pd.setTitle("Video Streamming Demo");
pd.setMessage("Buffering...");
pd.setIndeterminate(false);
pd.setCancelable(false);
pd.show();
try{
MediaController controller = new MediaController(Show.this);
controller.setAnchorView(view);
Uri vid = Uri.parse(URL);
view.setMediaController(controller);
view.setVideoURI(vid);
}catch(Exception e){
Log.e("Error", e.getMessage());
e.printStackTrace();
}
view.requestFocus();
view.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
pd.dismiss();
view.start();
}
});
}
}
6. below is the required xml file of the Application .
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/name1" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/name1" />
</RelativeLayout>
video.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
7. Now finally add internet permission to manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>

Comments ( 0 )
Subscribe Latest Information
Categories
Most Popular Posts
How to Withdraw Money from ATM Machine 7steps 1178778 Views
How to Create Chat Application in Android Studio 151633 Views
How to Create a Shopping Cart Application in Android 114496 Views
You May Like Also
How to make Realtime chat Application in Android 24919 Views
How to make a Simple Quiz App in Android 72246 Views
Android Floating Action Button tutorial 5564 Views
How to Create Overflow Menus in Android 14115 Views