Video Live Streaming in Android
Hello Frirends, Today i am going to post for Live Video streaming from server.
import
android.app.Activity;
import
android.app.ProgressDialog;
import
android.graphics.PixelFormat;
import
android.media.MediaPlayer;
import
android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import
android.widget.VideoView;
public class MainActivity extends Activity
{
private static ProgressDialog progressDialog;
String
videourl="";
VideoView
videoView ;
@Override
protected void onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView)
findViewById(R.id.video_View);
progressDialog = ProgressDialog.show(MainActivity.this, "", "Buffering
video...",true);
progressDialog.setCancelable(false);
PlayVideo();
}
private void PlayVideo()
{
try
{
getWindow().setFormat(PixelFormat.TRANSLUCENT);
MediaController
mediaController = new MediaController(MainActivity.this);
mediaController.setAnchorView(videoView);
Uri
video = Uri.parse(videourl);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener()
{
public void
onPrepared(MediaPlayer mp)
{
progressDialog.dismiss();
videoView.start();
}
});
}
catch(Exception e)
{
progressDialog.dismiss();
System.out.println("Video Play
Error :"+e.toString());
finish();
}
}
}
XML Layout:
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<VideoView
android:id="@+id/video_View"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
>
</VideoView>
</RelativeLayout>
</LinearLayout>
permission: <uses-permission android:name="android.permission.INTERNET" />
Hello, interesting example! Can you show how capture video from MediRecorder and show this video in current example?
ReplyDelete