How to create a video streaming from server in android

Android download video from URL and save to internal storage

 

Hi everyone in this article I am sharing How to create a video streaming from the server in android. These articles in a decision on VideoView and streaming facebook video. hare I am using WebView, VideoView. In Web View, you can open facebook and select a videoView for playing Fb video in your App.

In Other Word in these android tutorials, I share how to play video from the server using API. in your API have a JSON URL

Step 1: Open your Android Studio and Create an App Video Streaming.

firstly you can start your android studio and create an App with name video Streaming and open your java and XML file and used a VideoView in your activity. like if you have a youtube, Facebook, Instagram  Video link.

 String URL= https://www.youtube.com/watch?v=QnOcXQL2wDA&t=18s 

how to Play the Video Link in your App

Step 2: Open Your XML file and Add this Code.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="match_parent"
    android:background="@android:color/black"
    android:layout_height="match_parent">

    <VideoView
        android:id="@+id/videoView"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

</LinearLayout>

in the XML file, I add a video view Layout for play video.

Step 3: Open You Java File and add these code.

public class VideoPlayer extends AppCompatActivity {
    ProgressDialog pDialog;
    VideoView videoview;
   String vid_url ="https://www.youtube.com/watch?v=QnOcXQL2wDA&t=18s";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_player);
        Intent intent = getIntent();
       // String vid_url = intent.getStringExtra("video_url");
        videoview = (VideoView) findViewById(R.id.videoView);
        pDialog = new ProgressDialog(this);
        pDialog.setTitle("Video Stream");
        pDialog.setMessage("Buffering...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
        try {
            MediaController mediacontroller = new MediaController(this);
            mediacontroller.setAnchorView(videoview);
            Uri video = Uri.parse(vid_url);
            videoview.setMediaController(mediacontroller);
            videoview.setVideoURI(video);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        videoview.requestFocus();
        videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                VideoPlayer.this.pDialog.dismiss();
                VideoPlayer.this.videoview.start();
            }
        });
        videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
               finish();
            }
        });


    }
}

in java class implement VideoView and use a string of URL you can play this used is used in a string value and these complete and run you app and testing

Android download video from URL and save to internal storage

Facebooktwitterredditpinterestlinkedinmail
Recommended
  Hii Everyone in this Article I, am sharing how…