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.
Related
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.
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 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 have an android application consisting of 4 different screens. I am currently creating a new camera for each screen. Each of these screens have the same height and width. Is there a better way to handle this camera, rather than creating a new one for each screen, or is that necessary?
You could make a class like GameObjects and declare there your public static camera.
public static Camera camera;
Now in every screen you got, in the show method you would probably need to reset what you changed to it.
Example, if your camera was moving in a screen, you might want to set the position of the camera again in the show method (same thing about zoom, rotation etc).
You call your camera functions with GameObjects.camera, ex: GameObjects.camera.update();
I create a camera and spritebatch for every screen I have, and it's ok! Don't worry too much about it.
I don't really think that making just one camera is a good ideea anyways.
I need help to place a video at an arbitrary point on a playfield.
I am porting a game which takes place on a playfield - background with animated sprites superimposed. It's working fine.
The activity does a
// Set full screen view
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Off that, I run a View on which all the action takes place. The playfield adjusts in size and offset, depending on screen size and orientation. All that's working fine, and I scale the sprites and their positions accordingly.
But sometimes, I need to place a borderless video on top of an existing background at various specific points in the playfield, and everything I read in stackoverflow is about the video itself and not how to position it. Can anyone help? Where should I start looking?
Ah... It appears that I wanted AbsoluteLayout, which became deprecated in 2009. There is, however, more than one way to skin a cat. I just have to work a bit harder.