Video and images in SurfaceView

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Video and images in SurfaceView

Postby marielisacr » Mon Aug 25, 2008 8:21 pm

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:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  public static void setState(SurfaceHolder mHolder, SurfaceView
  2.  
  3. mPreview, Bitmap bitmap){
  4.  
  5.                try{
  6.  
  7.                    /*Center the image*/
  8.  
  9.                        double wP = mPreview.getWidth();
  10.  
  11.                        double hP = mPreview.getHeight();
  12.  
  13.                        double wB = bitmap.getWidth();
  14.  
  15.                        double hB = bitmap.getHeight();
  16.  
  17.                        double menos=1;
  18.  
  19.                        double i = 1;
  20.  
  21.                        double j = 1;
  22.  
  23.  
  24.  
  25.                        if (wP < wB)
  26.  
  27.                                i = wP/wB;
  28.  
  29.                        if (hP < hB)
  30.  
  31.                                j= hP/hB;
  32.  
  33.  
  34.  
  35.                        menos = Math.min(i,j);
  36.  
  37.  
  38.  
  39.                        int wTotal = (int)(wB*menos);
  40.  
  41.                        int hTotal = (int)(hB*menos);
  42.  
  43.                        int left = (int)((wP-wTotal)/2);
  44.  
  45.                        int top = (int)((hP-hTotal)/2);
  46.  
  47.  
  48.  
  49.                        Canvas canvas = mHolder.lockCanvas();
  50.  
  51.                        canvas.drawColor(Color.BLACK);
  52.  
  53.                        canvas.drawBitmap(bitmap, null, new Rect(left,top,wTotal+left,hTotal
  54.  
  55. +top), null);
  56.  
  57.                        mHolder.unlockCanvasAndPost(canvas);
  58.  
  59.                }catch(NullPointerException e){
  60.  
  61.                        Log.e("","NullPointerException in setState: ",e);
  62.  
  63.                }
  64.  
  65.        }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


2. the SurfaceHolder and SurfacePreview

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.    mPreview
  2.  
  3. =(SurfaceView)player.findViewById(R.id.picture);
  4.  
  5.                mHolder = mPreview.getHolder();
  6.  
  7.                mHolder.addCallback(this);
  8.  
  9.                mHolder.setFixedSize(mPreview.getWidth(), mPreview.getHeight());
  10.  
  11.                //mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


3. The mediaPlayer

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.    mediaPlayer = new MediaPlayer();
  2.  
  3.                        mediaPlayer.setAudioStreamType(2);
  4.  
  5.                        mediaPlayer.setDisplay(mHolder);
  6.  
  7.                        //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.
marielisacr
Junior Developer
Junior Developer
 
Posts: 13
Joined: Wed May 21, 2008 10:04 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 5 guests