Like Us on Facebook

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:  
 
  1. Create a New Android Studio project name VideoStream.
  2. Select minimum  API level 15 so it will run Maximum of Android device that are Active on google Play then click next.
  3. Select Blank Activity and your Activity name is VideoStreamActivity click next > click finish.
  4. 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();
}
});
}
}



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>



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>



7.  Now  finally  add internet  permission to manifest.xml
 
<uses-permission  android:name="android.permission.INTERNET"/>



 

Posted By UandBlog

UandBlog is a Global Leading source of Finance, Health, Lifestyle, Technology, Gaming and Programing and other information, it is a fastest growing blog for all , for latest post or information like us on facebook , follow on Twitter, Google+ and Pinterest.

Comments ( 0 )

    Leave a comment..

    Click to login.

    Subscribe Latest Information

    Most Popular Posts

    You May Like Also