i have made a media player and have called setDataSource(), setDisplay() and prepare() methods in onSurfaceCreated() method. Everything works fine when the view is rendered for the first time, if i rotate the screen, display disappears and only audio is availaible.How would I get it working? I have used video view for displaying video. Please help me with this issue.
From your question I can see that you are using a surface view which will re initiate when you rotate your screen. so you must set your screen mode to either landscape or portrait based on your requirement.
Else you must figure out some other way other than using surface view.
When you rotate the screen, Activity gets destroyed and a new one is created with a different configuration. If something doesn't work, it means that you should test your application in the landscape mode.
Related
I am using SurfaceView with ndk+openGL, when press screen rotate button of the emulator,
i received SurfaceChanged event from SurfaceHolder.Callback, then i post a redraw message via Handler, and the Handler redraws the screen with new display metrics via JNI native code, but the display is broken, as the picture shows.
I sure that the native OpenGL drawing code already draws one frame, after press rotate button and before screen rotation finish, but don't know why the display is broken.
I'm not so familiar with android, could someone help me. thanks.
EDIT:
when i make some touch events to trigger new frames, the display got fixed.
so i'm thinking is there a rotate finish event, so i can force draw one frame to fix this issue.
Problem solved.
Override the surfaceRedrawNeeded method of SurfaceHolder.Callback2, it will be called after rotate finished.
I am building this application where I need to get video with the camera and process it with openCV as well as show a view with 3D graphics being renderered in it.I am using two fragments. One for previewing the camera. And one for the 3D graphics.The problem is the 3d graphics view has to be fullscreen. I don't want the camera preview at all. I can show them side by side using linear layout. But I cannot totally hide the preview and make the 3d scene take up the whole screen. Even using relative layout causes the camera preview to tear through the 3d graphics view.
Simply put it, if the camera preview is not being shown, the CvCameraViewListener2.onCameraFrame() method is not called. And without that I don't receive any new frames to process.
The problem got solved. I really don't know how it got solved though. I woke up the next day and tried running the project and it ran perfectly without requiring to change anything.
I am struggling with a quite rare problem.
Here it goes:
I have a SurfaceView and there is a JNI-side thread that handling the rendering operations on it (Let say Render-thread). For "some" reason I need to rotate my drawings by myself inside the render-thread. To achieve this, the render thread queries the rotation status from the android framework. And I can see the rotated screen whenever the device is rotated, but there is a problem: if I rotate the device, the screen rendered by Render-Thread is rotated, but Android UIs (such as notification bar, toast message, etc) are not rotated (Of course!). To resolve this problem, I use setRequestedOrientation function to tell the Android to rotate my Activity. Then I can also see the properly rotated Android UIs. At this moment, my real problem happens: The race between Render-Thread and Android's screen rotation stuff (I guess surface flinger?).
Apparently, if I call setRequestedOrientation function, Android framework rotates the screen by itself, while my Render-thread is also drawing the rotated screen. And this results in a glitch.
My question here is that:
Is there a way to tell Android framework not to rotate the SurfaceView while I'm still calling setRequestedOrientation?
I try to use a Camera inside my app and I have a problem with proper handling of configuration changes. I know the proper way of handling configuration changes in a typical Activity (onSaveInstanceState etc...), but it's not the case here.
Think of my Activity as a fullscreen camera preview with an overlay shutter button and a frame which will be used to crop the image
What I'm trying to achieve (preview of a stock HTC Sense camera): http://youtu.be/uzfUJUNHY68
That is: the camera preview which is on TextureView should not be recreated on rotation, but the Activity should be orientation-aware, to position elements.
I'm pretty sure I don't want the Activity to be recreated on rotation. So I tried the android:configChanges approach. The problem is that onSurfaceTextureSizeChanged() is still called and the camera preview is rotated and the whole experience is not smooth (the preview lags for a moment and gets "recreated" or something).
I tried locking my Activity to landscape via android:screenOrientation="landscape", but this way onConfigurationChanged() is not called and I don't know how to position other views like in the video above. I guess I could listen to some accelerator events, but I'm pretty sure there is a better way. Is there?
Android camera source.
Lock activity rotation. On method onOrientationChanged of MyOrientationEventListener you can rotate, change positions of views etc. I think it's a best way.
Try with this option.
android:configChanges="keyboardHidden|orientation|screenSize"
On some devices, onPreviewFrame is not called if no SurfaceView was set to display the camera preview.
However, I handle the camera in a service, so I can't set a SurfaceView but I don't want to have visible preview anyway.
How can this be done? Can I programmatically create a SurfaceView and set it with Camera::setPreviewDisplay?
This must be possible or not?
It works on almost every phone without a SurfaceView but not on HTC One X and Google Nexus One...
According to this question, creating a SurfaceView in code works fine. Though I don't think you can create it through a service.
Another approach is to create a 1px-1px SurfaceView inside a RelativeLayout and hiding it with some other view on top of it. (visibility should still be VISIBLE). We use this trick for Path camera UI where we render preview buffers through OpenGL and it works fine.
According to documentation readily configured, visible and displayed surface view is necessary to activate camera preview. It may be overlayued though
From API 11 on, you can use a SurfaceTexture instead of a SurfaceView to get frames from the camera. Then, instead of using Camera.setPreviewDisplay, simply use Camera.setPreviewTexture.
This answer as well as this one discuss this point.