android - Camera Preview: No errors but no picture :-( -


have read books , hints, got rid of compile errors , warnings , put in debug statements.

package com.cit.broadcastsim;  import java.io.ioexception;  import android.app.activity; import android.hardware.camera; import android.os.bundle; import android.util.log; import android.view.surfaceholder; import android.view.surfaceview;  public class broadcastactivity extends activity implements surfaceholder.callback {   public camera mycamera;   @override   public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.broadcast);  // inflate broadcast.xml file      log.d("broadcast", "creating activity");     surfaceview camerasurface = (surfaceview)findviewbyid(r.id.camerasurface);     surfaceholder cameraholder = camerasurface.getholder();     cameraholder.settype(surfaceholder.surface_type_push_buffers);     cameraholder.addcallback(this);     log.d("broadcast", "now wait callbacks"); }     public void surfacecreated(surfaceholder holder) {     // surface created, possible set preview     log.d("broadcast", "surface created");     try {       log.d("broadcast","camera: not null");       mycamera = camera.open();       mycamera.setpreviewdisplay(holder);       mycamera.startpreview();       } catch (ioexception e) {         log.d("broadcast", e.getmessage());       }   }    public void surfacedestroyed(surfaceholder holder) {     log.d("broadcast", "surface destroyed");     mycamera.stoppreview();     mycamera.release();   }    public void surfacechanged(surfaceholder holder, int i, int j, int k) {     log.d("broadcast", "surface changed");     mycamera.stoppreview();     mycamera.release();   } } 

in ddms debugger, log message 'creating activity' followed 'now wait callbacks' , nothing more in terms of debug messages think callback not working - life of me can't see have got wrong.

in manifest have

the activity xml page has

<textview     android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:text="@string/broadcast"   /> <surfaceview   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:id="@+id/camerasurface"    /> </linearlayout> 

finally, on android phone (htc wildfire), page loads, textview message appears @ top left , all.

should mention new platform , accept might have missed very basic.

any ideas/comments appreciated,

oliver

haven't got enough time explain (meeting friends in few minutes). added functions "surfacechanged()" (this should start preview).

therefore don't need mcam.startpreview() in "surfacecreated()"

    public void surfacecreated(surfaceholder holder) {     // surface created, possible set preview     log.d("broadcast", "surface created");     try {       log.d("broadcast","camera: not null");       mcam = camera.open();       mcam.setpreviewdisplay(holder);       //mycamera.startpreview();       } catch (ioexception e) {         log.d("broadcast", e.getmessage());       }   }    public void surfacedestroyed(surfaceholder holder) {     log.d("broadcast", "surface destroyed");     mcam.stoppreview();     mcam.release();   }    public void surfacechanged(surfaceholder holder, int i, int j, int k) {       camera.parameters parameters = mcam.getparameters();     list<size> previewsizes = parameters.getsupportedpreviewsizes();     size bestsize = null;     int bestdiff = 0;     int diff = 0;     (size size : previewsizes) {             diff = math.abs(k - size.height) + math.abs(j - size.width);         if (bestsize == null || diff < bestdiff) {                 bestsize = size;                 bestdiff = diff;         }         parameters.setpreviewsize(bestsize.width, bestsize.height);         mcam.setparameters(parameters);     }      //start preview of camera       mcam.startpreview();   } 

xml-file (you did little copy & paste error)

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     > <textview       android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:text="@string/hello"     /> 

hope :) think, via setting orientation, change camera picture portrait mode. :) (it's landscape right now)


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -