I'm using exoplayer in my project, when switching mediasource i just use
player.stop();
player.prepare(mediaSource);
This causes approx. 0.5 seconds black screen until it switches video.
Is there a way to tell exoplayer to retain last frame from previous video (instead of 0.5 sec black screen) until new video is started?
simpleExoPlayerView.setShutterBackgroundColor(Color.TRANSPARENT);
Exoplayer's developers have provided solution to this issue here.
Simply add this line using your SimplePlayerView instance
playerView.setKeepContentOnPlayerReset(true);
Alternatively, you can also do this via your layout.xml file,
app:keep_content_on_player_reset="true"
In my case I'm having a single instance on SimpleExoPlayer and i used to set this via setPlayer in exoplayer view with changed video url's but having blank screen when scroll back to previously played videos.
I just used setPlayer(null) before again setting the player in exoplayerview and the black screen issue fixed.
Related
I am using vlcj to play video in a Java Swing application. I want to be able to switch from one VideoSurface to another during playback. This is working fine if I first stop the vlcj mediaPlayer, assign a new VideoSurface to it and then restart the player again. The thing is, I want the switch to work seamlessly. If I skip the stop/restart part, I am seeing a grey screen with no video being displayed in the newly assigned VideoSurface. According to the documentation, setting a new surface should be possible. Am I missing something?
final Canvas canvas1 = new Canvas();
final Canvas canvas2 = new Canvas();
ComponentVideoSurface videoSurface = null;
videoSurface = factory.newVideoSurface(canvas1);
mediaPlayer.videoSurface().set(videoSurface);
// start playback...
videoSurface = factory.newVideoSurface(canvas2);
mediaPlayer.videoSurface().set(videoSurface);
There is no video output on surface2. If I switch back to surface1, I can see it.
Thanks in advance!
Edit:
I also tried removing the first canvas from its Container and adding the same reference to another one (so, I did not set a new VideoSurface, I just moved the existing one into another Container), but the effect was the same.
The answer is simply that you can not switch video surface while playing media.
(Well, I suppose you can switch it, but it won't take effect.)
You can not "re-parent" the video surface to a different container either, so for example it won't work in a docking window framework without stopping and restarting video.
My usual recommendation for something like this is instead to write a custom LayoutManager that can shift your various components around without changing the actual video surface associated to the media player.
I recording video using MediaRecorder.When using back-camera,it working fine,but when using front camera,the video captured is being flipped/inverse.Means that the item in right,will appear on the left.The camera preview is working fine,just final captured video flipped.
Here is the camera preview looks like
But the final video appear like this(all the item in left hand side,appear on right hand side)
What I tried so far:
I tried to apply the matrix when prepare recorder,but it seems does change anything.
private boolean prepareRecorder(int cameraId){
//# Create a new instance of MediaRecorder
mRecorder = new MediaRecorder();
setCameraDisplayOrientation(this,cameraId,mCamera);
int angle = getVideoOrientationAngle(this,cameraId);
mRecorder.setOrientationHint(angle);
if(cameraId == Camera.CameraInfo.CAMERA_FACING_FRONT){
Matrix matrix = new Matrix();
matrix.preScale(1.0f,-1.0f);
}
//all other code to prepare recorder here
}
I already read for all this question below,but all this seems didnt solve my problem.For information,I using SurfaceView for the camera preview,so this question here doesn't help.
1) Android flip front camera mirror flipped video
2) How to keep android from inverting the image from the front facing camera?
3) Prevent flipping of the front facing camera
So my question is :
1) How to capture a video by front camera which the video not being inverse(exactly the same with camera preview)?
2) How to achieve this when the Camera preview is using SurfaceView but not TextureView ? (cause all the question I mention above,tell about using TextureView)
All possible solution is mostly welcome..Tq
EDIT
I made 2 short video clip to clarify the problem,please download and take a look
1) The video during camera preview of recording
2) The video of the final product of recording
So, if the system camera app produces video similar to your app, you didn't do something wrong. Now it's time to understand what happens to front-facing camera video recording.
The front facing camera is not different from the rear facing camera in the way it captures still pictures or video. There is a difference how the phone displays camera preview on the screen. To make it look more natural to the user, Android (and all other systems) mirrors the preview, so that you can see yourself as if in a mirror.
It is important to understand that this only applies to the way the preview is presented to you. If you pick up any video conferencing app, connect two devices that you hold in two hands, and look at yourself, you will see to your surprise that the two instances of yourself are flipped.
This is not a bug, this is the natural way to present the video to the other party.
See the sketch:
This is how you see the scene:
This is how your peer sees the same scene
Normally, recording of a video is done from the point if view of your peer, as in the second picture. This is the natural setup for, e.g., video conferencing.
But Snapchat and some other social apps choose to store the front-facing video clip as if you record it from the mirror (as if the recorder is in your hand on the first picture). Some people like this feature, others hate it (see https://forums.androidcentral.com/general-help-how/664539-front-camera-pics-mirrored-reversed-only-snapchat.html and https://www.reddit.com/r/nexus6/comments/3846ay/has_anyone_found_a_fix_for_snapchat_flipping)
You cannot use MediaRecorder for that. You can use the lower-level API of MediaCodec to record processed frames. You need to flip each frame 'manually', and this may be a significant performance hit, because normally the MediaRecorder 'connects' the camera to hardware encoder in a very efficient way, without need even to copy the pixels to user memory. This answer shows how you can manipulate the way camera is rendered to texture.
You can achieve this by recording video manually from surface view.
In such case preview and recording will match exactly.
I've been using this library for this purpose:
https://github.com/spaceLenny/recordablesurfaceview
Here is the guide how to use it (not with camera but with OpenGL drawing): https://withintent.uncorkedstudios.com/recording-screen-video-on-android-with-recordablesurfaceview-451c9daa213e
I have an application that scan barcode with the Android device cameras. I take the example program here: https://github.com/journeyapps/zxing-android-embedded
Now, I want to scan a barcode with my device front camera.
On that sample solution there's a button that allow you to take a barcode by front camera, but the problem is that the Preview image of camera is "flipped", like on a mirror, and so the application can't read the barcode.
Is there a method to overcome this problem and to make sure that the recorded image is displayed correctly?
This mirroring is hardcoded into the camera service, and can not be disabled.
Try applying a transformation matrix to a TextureView. As per Prevent flipping of the front facing camera
This works for API level >= 14
I have developed one desktop application using swing under which i have used JavaFx components, i have a few camera which i drag to the 2*2 layout view, it's working fine, now as soon as i changed the layout from 2*2 to 4*4, the view gets changed, then later on the dragged camera remain same on the canvas, but the streaming coming from the camera initially stops and then starts, i just want the video stream coming from the camera to remain consistent, without restarting it, what i have did now, is to release the Media player , Created the updated Canvas and Add it into the panel, but i guess it's not a proper solution, can anyone help me out with this issue, thanks well in advance.
Any kind of help is highly appreciable.
You can not remove the media player Canvas from the frame component hierarchy, nor can you hide it.
You must do something else like minimise it's size to 0,0 use a custom layout manager and move it's position to 0,0 or -1,-1 may work.
To emulate hiding, you could use a CardLayout with a video view and a blank view and switch between them.
There's an example in the vlcj test sources that shows one approach: https://github.com/caprica/vlcj/blob/master/src/test/java/uk/co/caprica/vlcj/test/layout/AdaptiveLayoutTest.java
I used to have a nice little fragment that loaded the camera in a frame (An image overlayed on top in a frame layout). After doing some refactoring to my code( which I have gone over Incessantly), I suddenly noticed that my camera didn't work.The SurfaceView that was supposed to show the camera was blank.
Over the last four hours, I added null checks and breakpoints everywhere. I could not find the source of the breakage. So then I swapped out most of my code for a line by line copy of the CommonsWare Camera example. The main difference is that my version was in a Fragment instead of an activity.
I understood most(if not all) of it while re-implementing it, and made it fit my current fragment based system. While it did not fix my bug, after a while I discovered that moving my SurfaceView above my ImageView worked. However, it did not provide the intended overlay effect as the frame was now effectively over the surface.
...Until I found that I had set the fragment container to a Hardware layer and forgot to return it to normal.
Beware this line:
findViewById(R.id.fragment_container).setLayerType(View.LAYER_TYPE_HARDWARE, null);
It messes with camera rendering.
Hopefully this helps some other poor soul.