Hi, I am working in an Android application, now I am trying to migrate
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:
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);
}
}
2. the SurfaceHolder and SurfacePreview
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);
3. The mediaPlayer
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(2);
mediaPlayer.setDisplay(mHolder);
//mediaPlayer.setDisplay(mPreview.getHolder().getSurface());
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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---