Well I've done an app in android studio and this app has a video running in background for the Login. The video is in a VideoView and works perfectly but when I was testing it in my phone while I was playing music I noticed that it pauses the music player. How can I solve this?
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
vid = findViewById(R.id.videoView2);
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.video);
vid.setVideoURI(uri);
vid.start();
vid.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
usuRut = findViewById(R.id.usuRut);
girPass = findViewById(R.id.usuPass);
girId = findViewById(R.id.girId);
}
This is where I run the video.
videoView.setAudioFocusRequest(AudioManager.AUDIOFOCUS_NONE);
You need to use the setAudioFocusRequest method. It's only available from API level 26
Related
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();
}
});
}
I'm doing an android app that plays video from live camera.
I can watch live, but it comes back 1.5 seconds.
We do not want.
I used standard settings:
public class MainActivity extends AppCompatActivity {
VideoView videoView;
String videoUrl = "rtsp://admin:admin#192.168.1.125/live/0/h264.sdp";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) this.findViewById(R.id.rtspVideo);
RtspStream(videoUrl);
}
private void RtspStream(String rtspUrl) {
videoView.setVideoURI(Uri.parse(rtspUrl));
videoView.setZOrderOnTop(false);
videoView.requestFocus();
videoView.postInvalidateDelayed(0);
videoView.start();
}
}
I think it's about buffer.
How can I solve the problem of coming back?
how can the library or application settings be used?
I am new to android and want to play videos one after another simultaneously so that it looks like continuous video.
I have found this link on stackoverflow very helpful. how-to-play-videos-one-after-another-simultaneously
When I am using this then though I am able to play videos one after another,
But switching from one segment to other results in pause the video for a second before playing next one. So It don't looks like continuous videos due to this.
Please help me to resolve my problem.
Here is my Code.
public class VideoActivity extends Activity{
VideoView videoView, videoView1;
MediaController mc;
int count = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
videoView = (VideoView) findViewById(R.id.VVSimpleVideo);
setup();
videoView.setOnCompletionListener(completionListener);
}
public void setup() {
String _path = "/mnt/sdcard/Video/"+count+".mp4";
videoView.setVideoPath(_path);
videoView.start();
count++;
}
private OnCompletionListener completionListener=new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.stop();
setup();
}
};
}
Now I have tried to play by taking two instances of VideoView class.
Tried to play the first video by first player and second video by second player,
Third video from first player and fourth video from second player and so on.
But still I am not able to play the video smoothly and the same problem exist.
Here is my code with double player.
public class VideoActivity extends Activity{
VideoView videoView, videoView1;
MediaController mc;
int count = 0;
String _path;
String _path1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
videoView = (VideoView) findViewById(R.id.VVSimpleVideo);
_path = "/mnt/sdcard/Video/"+count+".mp4";
videoView.setVideoPath(_path);
videoView.start();
//setup();
videoView.setOnCompletionListener(completionListener);
videoView1 = (VideoView) findViewById(R.id.VVSimpleVideo);
videoView1.setOnCompletionListener(completionListener1);
count++;
_path1 = "/mnt/sdcard/Video/"+count+".mp4";
videoView1.setVideoPath(_path1);
}
public void setup() {
videoView.start();
count++;
_path1 = "/mnt/sdcard/Video/"+count+".mp4";
videoView1.setVideoPath(_path1);
}
public void setup1() {
videoView1.start();
count++;
_path = "/mnt/sdcard/Video/"+count+".mp4";
videoView.setVideoPath(_path);
}
private OnCompletionListener completionListener=new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.stop();
setup1();
}
};
private OnCompletionListener completionListener1=new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.stop();
setup();
}
};
}
You're not really using two VideoViews at all, you're assigning both VideoView and VideoView1 to R.id.VVSimpleVideo, so they are the same object. That means each time you hit onCompletion, it's setting itself up all over again, instead of setting up one and playing the other.
Try creating two separate VideoView objects in your layout. Have one set to VISIBLE and one set to GONE/INVISIBLE, and swap when you want to change.
I can't guarantee it will make it "seamless", though, since that's an almost impossible task. Even most desktop media players aren't truly seamless. It just depends on what tolerance you have for seams.
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.
I am trying to play a video that is passed from a WebView in a VideoView. It works, except VideoView does not want to read it. I keep getting the error:
"Sorry, this video cannot be played."
Here is the code for the VideoView:
public class VideoHandler extends Activity {
WebView myWebView;
VideoView myVideoView;
WebChromeClient chromeClient;
WebViewClient wvClient;
Intent in;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_player);
myVideoView = (VideoView) findViewById(R.id.videoview);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(myVideoView);
String video = (MNWVMainPage.myWebView.getUrl());
myVideoView.setMediaController(mediaController);
myVideoView.setVideoPath(video);
myVideoView.start();
myVideoView.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.release();
setContentView(R.layout.mnwv_main);
}
});
}
}
Why wont this load the video?
From just reading from your code, I can see no error.
Can you check a few things:
Does the video align to the format list here?
Have you open the camera/ another VideoView? Even if you release them, the buffer seems to need some time to be actually released.