it to version 0.9, but I am having some problems. I would like to use
the same SurfaceView to put videos and images.
In first place I would like to know how can I use a SurfaceView to
display bitmaps and videos. For example, I would like to put an image
of loading while I download the video, and when it is ready play it.
The problem is that when I use
myHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS), I can use
lockCanvas, so I can put any image even when I set another type.
(This used to work in m5)
Here is what I am using:
1. To set the bitmap in the SurfaceHolder:
Using java Syntax Highlighting
- public static void setState(SurfaceHolder mHolder, SurfaceView
- mPreview, Bitmap bitmap){
- try{
- /*Center the image*/
- double wP = mPreview.getWidth();
- double hP = mPreview.getHeight();
- double wB = bitmap.getWidth();
- double hB = bitmap.getHeight();
- double menos=1;
- double i = 1;
- double j = 1;
- if (wP < wB)
- i = wP/wB;
- if (hP < hB)
- j= hP/hB;
- menos = Math.min(i,j);
- int wTotal = (int)(wB*menos);
- int hTotal = (int)(hB*menos);
- int left = (int)((wP-wTotal)/2);
- int top = (int)((hP-hTotal)/2);
- Canvas canvas = mHolder.lockCanvas();
- canvas.drawColor(Color.BLACK);
- canvas.drawBitmap(bitmap, null, new Rect(left,top,wTotal+left,hTotal
- +top), null);
- mHolder.unlockCanvasAndPost(canvas);
- }catch(NullPointerException e){
- Log.e("","NullPointerException in setState: ",e);
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
2. the SurfaceHolder and SurfacePreview
Using java Syntax Highlighting
- mPreview
- =(SurfaceView)player.findViewById(R.id.picture);
- mHolder = mPreview.getHolder();
- mHolder.addCallback(this);
- mHolder.setFixedSize(mPreview.getWidth(), mPreview.getHeight());
- //mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
3. The mediaPlayer
Using java Syntax Highlighting
- mediaPlayer = new MediaPlayer();
- mediaPlayer.setAudioStreamType(2);
- mediaPlayer.setDisplay(mHolder);
- //mediaPlayer.setDisplay(mPreview.getHolder().getSurface());
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
And another quick question, how can I change the size of the display
video to the size of the SurfaceView?.
Thanks so much and I hope someone can help me.

