Android SurfaceView causes screen flickering

I am working on an Android multimedia video processing application and am having a problem. I use the FragmentPagerAdapter class with several different fragments inside for the various stages of video processing.

My first Fragment contains SurfaceView and MediaPlayer , which serve it along with various playback controls. My problem arises when I scroll to fragment 1 (with SurfaceView) to fragment 2 (currently empty). If I have not called start() yet, nothing unusual happens and I can navigate normally between fragments. However, when I call start() , the whole screen starts blinking and SurfaceView on when I scroll through the next Fragment , even if I put the MediaPlayer on standby and did not SurfaceView frames to the SurfaceView . The only thing that stops this is to destroy the surface together with the displayed view by moving it to the third Fragment so that the FragmentPagerAdapter destroys the Fragment alone or exits the application through the home or back button so that the view is destroyed.

I canโ€™t understand in my life why this happens, except that the SurfaceView rendering stream somehow interferes with the main UI thread. Nothing unusual appears on LogCat, so I'm a bit stuck. I am using Galaxy Nexus with android 4.1 as test equipment.

Any help would be appreciated!

Jt

UPDATE:. At the moment, I managed to find a workaround by overriding the setPrimaryItem() method in the FragmentPagerAdapter to call a method that removes SurfaceView from the hierarchy (using removeView() in the LinearLayout container) when the Fragment video player stops displaying and then restores SurfaceView again when it active again. When all this happens, unfortunately, it's still a little bit, therefore, if someone has additional thoughts, I would be grateful!

+7
source share
1 answer

From Android Developer Blog

This [SurfaceView] widget works by creating a new window located outside your applicationโ€™s window. He then punches a hole in the application window to open a new window.

Since SurfaceViews content does not live in the application window, it cannot be effectively transformed (moved, scaled, rotated). This makes it difficult to use SurfaceView inside a ListView or ScrollView.

The solution is to use TextureView if you are creating for version 4.0 or higher. If you're interested in using TextureView to display a video, this stream might be useful.

+4
source

All Articles