play 2 videoview overlap in one layout - android

I want to make 2 videoviews overlap in one layout like this
This my code:
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) {
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
.create();
// Setting Dialog Title
alertDialog.setTitle("Alert Dialog");
// Setting Dialog Message
alertDialog.setMessage("Video Play Error :" + e.toString());
progressDialog.dismiss();
System.out.println("Video Play Error :" + e.toString());
finish();
}
My problem is: video 1 can play, but video 2 not play. If I minimize my application and I maximize again, 2 videos can run at the same time.
Please help , thanks before!

VideView is a surface view that should not overlay each other. The order of the components in the layout is not considered during rendering. The solution is to use the setZOrderMediaOverlay() method to inform the system that video2 is above any other surface. In your code I can't see video2 but you should include the following line in its initialization.
video2View.setZOrderMediaOverlay(true);

Related

Videoview not working in samsung device only for some video

I used Videoview in my app. Its working fine in all device. But for there is some link, like given one, which doesn't work in Samsung device only.
For other all device even with very low configuration, it's working fine.
Please don't share videoview example etc. Please give a logical answer.
Video Link: Video Link Here
private void play(){
pd = new ProgressDialog(activity);
pd.setMessage(getString(R.string.buffering_video));
pd.show();
Uri uri = Uri.parse(video_url);
videoview.setVideoURI(uri);
videoview.requestFocus();
videoview.start();
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
//close the progress dialog when buffering is done
pd.dismiss();
}
});
}

Auto Play Videos (List View)

How to do an autoplay like facebook in a listview, only one video at a time, and pause it when it comes out of focus.
Below is the code for playing video after OnClick, on Video View in Another Activity, I want it like Facebook that user scrolls and Video plays Automatically.
Videos_URL = intent.getExtras().getString("VideoUrl");
// Find your VideoView in your video_main.xml layout
myVideoView = (VideoView) findViewById(R.id.videoview);
if (mediaControls == null) {
mediaControls = new MediaController(this);
}
// Create a progressbar
progressDialog = new ProgressDialog(this);
// Set progressbar title
progressDialog.setTitle("APPNAME Video ");
// Set progressbar message
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
// Show progressbar
// Show progressbar
progressDialog.show();
try {
Uri video = Uri.parse(Videos_URL);
myVideoView.setVideoURI(video);
myVideoView.setMediaController(mediaControls);
myVideoView.start();
Is it possible to get Auto Play in Video View in Android??
On getview method of adapter you do like this,
it will auto play video when it will come on view.
videoView.setVideoPath(videoPath);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(final MediaPlayer mp) {
//seekbar.
mp.start();
} catch (Exception e) {
e.printStackTrace();
}

How to Set android video width and height

i have issues in android video playing. am geting videos from server and set to videoview but videos is playing in backgroung am not able to see that videos ,please refer my code what i have tried.
XML FILE
<LinearLayout 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/eventDetailsPage_videosView"
android:layout_width="160dp"
android:layout_height="100dp"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:background="#drawable/ic_eventvideo_image" />
</LinearLayout>
Java Class
Uri uri=Uri.parse(mEventDetailsUtil1.getAttachmentsUrls().get(0).getAttach_url());
VideoView mVideosView = (VideoView) findViewById(R.id.eventDetailsPage_videosView);
MediaController mc = new MediaController(this);
mc.setAnchorView(mVideosView);
mc.setMediaPlayer(mVideosView);
mVideosView.setMediaController(mc);
mVideosView.setVideoURI(uri);
mVideosView.requestFocus();
mVideosView.start();
the video is playing when opening the activity , but i don't want like that i need when i click on VideoView i need to open video full screen.
Try this :
VideoView mVideoview;
mVideoview = (VideoView) findViewById(R.id.VideoView);
mPlayServer = (Button) findViewById(R.id.mServerbutton);
mPlayServer.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
playVideo(SERVER_VIDEO_URL);
}
});
private void playVideo(SERVER_VIDEO_URL)
try {
// Start the MediaController
MediaController mediacontroller = new MediaController(mContext);
mediacontroller.setAnchorView(mVideoview);
// Get the URL from String VideoURL
mVideo = Uri.parse(SERVER_VIDEO_URL);
mVideoview.setMediaController(mediacontroller);
mVideoview.setVideoURI(mVideo);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
mVideoview.requestFocus();
mVideoview.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
mVideoview.start();
}
});
mVideoview.setOnCompletionListener(new OnCompletionListener() {
// Called when video is completed
public void onCompletion(MediaPlayer mp) {
}
});
}
To show in fullscreen use video view in new xml file with height and width as fill parent and start new activity with Intent.
Hope this helps.
Android does not support the resizing of videos, you may want to look into a Third Party library that you can utilize. By default android does not have this. I got the same problem while applying controls to video player.

Android MediaPlayer freezes after seeking a new video position

I load a .mp4 on a VideoView, all things go fine until I drag the seekbar point to a new position, so the MediaPlayer starts to buffering and then the app freezes (not crash, just freeze) with an error message:
"Can't play video"
This is the code:
try {
// Start the MediaController
controller.setAnchorView(videoView);
// Get the URL from String VideoURL
Uri video = Uri.parse(getIntent().getExtras().getString("video"));
videoView.setMediaController(controller);
videoView.setVideoURI(video);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
pDialog.dismiss();
videoView.start();
}
});
No errors if I seek an already-buffered position. Only with no-buffered positions.
Error log:
Attempt to perform seekTo in wrong state: mPlayer=0x5c149090, mCurrentState=0
E/MediaPlayer(17339): error (1, -110)
E/MediaPlayer(17339): Error (1,-110)
D/VideoView(17339): Error: 1,-110

Streaming video with videoview

My code below to 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 video's format not support by android phone or pad.
It show a dialog, and not show the screen.
But it still streaming with black screen.
I want to get the error message, and access as an exception.
But I don't know how to get it?
Another problem is that the streaming may crash cause by low speed wifi.
How to check it to wait while low speed wifi?
try this code,it work,
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();
}
}
}
It depends on which Android Version you are developing your application on. There are certain devices which do not support running .mp4 file. Go through Android Media support for more information. Check if you can play any .3gp files or not.
You shouldn't play the video instantly. Add OnPrepared listener to the video view and start the video playing after it. With MediaPlayer you could keep track of the buffering state and stop the video for a while when its not yet downloaded. Please have a look at this guide.
Try Intent to avoid that error. or put try catch in your block.
VideoView can only Stream 3gp videos but i recommend this code to stream your 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 watch Android Video Streaming Tutorial.

Categories

Resources