Streaming video from video

My code is below for streaming video:

VideoView vv = (VideoView)this.findViewById(R.id.screen_video); Uri uri = Uri.parse(URL); vv.setVideoURI(uri); vv.start(); 

It works. But if the URL format is not supported by the Android phone or pad. It shows a dialog, not a screen. But it is still streaming with a black screen. I want to get an error message and access as an exception. But I do not know how to get this?

Another problem is that streaming can cause crashes when using low-speed Wi-Fi. How to check it is waiting for low Wi-Fi speed?

+4
source share
4 answers

try this code, it works,

 public class PlayVideo extends Activity { private String videoPath ="url"; private static ProgressDialog progressDialog; String videourl; VideoView videoView ; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.play_video); videoView = (VideoView) findViewById(R.id.videoView); progressDialog = ProgressDialog.show(PlayVideo.this, "", "Buffering video...", true); progressDialog.setCancelable(true); PlayVideo(); } private void PlayVideo() { try { getWindow().setFormat(PixelFormat.TRANSLUCENT); MediaController mediaController = new MediaController(PlayVideo.this); mediaController.setAnchorView(videoView); Uri video = Uri.parse(videoPath ); 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(); } } } 
+11
source

It depends on which version of Android you are developing your application for. There are certain devices that do not support the launch of the .mp4 file. Go through Android Media Support for more information. Check if you can play with any .3gp files or not.

+2
source

You do not have to play the video right away. Add the OnPrepared listener to the video view mode and start playing the video after it. With MediaPlayer, you can monitor buffering status and pause the video for a while while it is not already loaded. Please read this guide.

+1
source

Try the intent to avoid this error. or put try catch in your block. VideoView can only play Stream 3gp videos, but I recommend this code for streaming video.

 public void onCreate(Bundle savedInstanceState){ setContentView(R.layout.main); String videourl = "http://something.com/blah.mp4"; Uri uri = Uri.parse(videourl); Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.setDataAndType(uri, "video/mp4"); startActivity(intent); } 

Or Click here to view the Android streaming tutorial .

+1
source

Source: https://habr.com/ru/post/1402177/


All Articles