Questions tagged [surfaceview]

SurfaceView is a widget on the Android platform which provides a dedicated drawing surface.

Android's SurfaceView class provides a dedicated drawing surface embedded inside of a View hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen.

A SurfaceView has two parts: the Surface, and the View. The Surface is a separate layer, independent of the View UI layer; by default it is positioned behind the View layer. The View works like any other View element, and is usually completely transparent, serving only to interact with other View elements during layout. In some situations it can be useful to draw on the View (e.g. for a static mask).

Because the Surface is an independent layer, it can be updated outside of the usual invalidate/refresh View cycle, on a dedicated thread.

Allocation of a display Surface is performed by the Window Manager. This requires an IPC round-trip, so the availability of and changes to Surfaces are reported through callbacks. This also makes it difficult to move a SurfaceView around smoothly, as the position of the View and position of the Surface may not update on the same frame.

Other View elements can be positioned to overlap the SurfaceView, including interactive elements like buttons. The Surface's Z-order can be altered to place it on top of the View layer. It isn't possible to sandwich the Surface between View elements; if you need that, consider TextureView instead.

The transparent region that makes the surface visible is based on the layout positions in the view hierarchy. If the post-layout transform properties are used to draw a sibling view on top of the SurfaceView, the view may not be properly composited with the surface.

For many applications, a custom view is a better choice.

Detailed information about SurfaceView can be found in the system-level graphics architecture document.

2733 questions
16
votes
1 answer

How to pass Camera preview to the Surface created by MediaCodec.createInputSurface()?

Ideally I'd like to accomplish two goals: Pass the Camera preview data to a MediaCodec encoder via a Surface. I can create the Surface using MediaCodec.createInputSurface() but the Camera.setPreviewDisplay() takes a SurfaceHolder, not a Surface. …
Andrew Cottrell
  • 3,312
  • 3
  • 26
  • 41
15
votes
4 answers

Rotating an android VideoView

My application offers only Portrait mode. In a portrait activity I have a fullscreen VideoView. What I want to do is rotate the VideoView ( the actual video, videobuffer) 90 degrees at Landscape mode. Enabling activity to be on Lanscape mode is not…
weakwire
  • 9,284
  • 8
  • 53
  • 78
15
votes
3 answers

Programming with SurfaceView and thread strategy for game development

I am using a SurfaceView and a rendering thread to develop a game based on structure like LunarLander. However, I faced many problems, and here I want to point them all out. I wish anyone who want to develop a game won't need to struggle with them…
Steven Shih
  • 645
  • 1
  • 10
  • 22
15
votes
7 answers

how to pause and resume a surfaceView thread

I have a surfaceView setup and running, but when I resume it I get an error that the thread has already been started. What's the proper way to handle when the app goes to the background and then back to the foreground? I've tinkered around and…
jfisk
  • 6,125
  • 20
  • 77
  • 113
15
votes
1 answer

Android Warning: CHECK surface infomation creating=false

When I run my Android application I noticed the following warning in the LogCat window: Tag: SurfaceView Text: CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true…
magritte
  • 7,396
  • 10
  • 59
  • 79
15
votes
5 answers

how to clear surface holder when media player is finished?

I made a video player with surfaceview and mediaplayer. i have 10 videos and 10 buttons. if click on each buttons, each videos are playing. here is my code.. //onCreate holder =…
beginners
  • 253
  • 1
  • 4
  • 18
14
votes
5 answers

How to play multiple video files simultaneously in one layout side by side in different view in Android

In Android, I created a layout with three surface view side by side, and I want to play one video file with different media player simultaneously. But one problem I faced that none of three can play that video simultaneously. One or two of them…
14
votes
4 answers

How can I make a SurfaceView larger than the screen?

I would like to effectively make a simple digital zoom for the camera preview, so I thought I would simply resize my SurfaceView to be larger than the screen. Other questions (such as 3813049) seem to indicate that this is easy, so I created the…
Ben
  • 1,272
  • 13
  • 28
14
votes
4 answers

lockCanvas() really slow

Testing my game on a slower device (Orange San Francisco aka ZTE Blade) and I have been getting an appalling frame rate. I put some debug code into the draw loop and discovered the following line is taking over 100ms: c =…
Kevin
  • 1,200
  • 1
  • 11
  • 19
14
votes
2 answers

Bad performance when drawing continuously in CustomView

Use case: I need to draw hundred lines and a few pieces of text on my view. I need to give a scrolling effect, for which I capture the ACTION_MOVE event and redraw all the lines with the updated points. To get the desire result I tried with…
VijayRaj
  • 425
  • 1
  • 4
  • 22
14
votes
2 answers

Resizing surface view for aspect ratio change in video display in android

I am working on a video conferencing project. My video display is using surface view. Now during a video call there is a chance of aspect ratio change for the incoming frames. So i have tried the following code for it public void surfaceResize() { …
Kevin K
  • 589
  • 2
  • 7
  • 28
14
votes
2 answers

Taking screenshot programmatically doesnt capture the contents of surfaceVIew

I have an app that I want to be able to capture a screenshot. The background of the layout is a surfaceView that shows video from the rear camera. The following code is able to take a screenshot but the contents of the surfaceView is saved as black.…
mremremre1
  • 1,036
  • 3
  • 16
  • 34
13
votes
2 answers

Color banding only on Android 4.0+

On emulators running Android 4.0 or 4.0.3, I am seeing horrible colour banding which I can't seem to get rid of. On every other Android version I have tested, gradients look smooth. I have a SurfaceView which is configured as RGBX_8888, and the…
13
votes
3 answers

Canvas in SurfaceView - hardware acceleration

I'm developing on ICS and trying to understand why a Canvas.isHardwareAccelerated() will always return FALSE when using a Canvas inside a SurfaceView. I've tried a very basic example like…
user1019096
  • 135
  • 1
  • 7
13
votes
4 answers

How to get DisplayCutout height when creating an Activity?

I have a game with full screen SurfaceView (Portrait) and thread that renders continously on the surface. The SurfaceView is initialized onCreate and its size is determined by the width and height of the screen in pixels. After it's created, it is…
luben
  • 2,512
  • 4
  • 30
  • 41