Basically I'm trying to pass the surface which is created by Java Application to my native library. When I use the GetIntField() function to get the surface object (ISurface) function, the object passed by app is becoimg null. Anyone faced similar issues?
Thanks, Sandeep On Mar 18, 2:31 pm, Sandy <snarr...@gmail.com> wrote: > I'm having issues when trying to use the java surface on the native > side. However, when I create the surface on the native side, the media > playback is fine. > > The following are the things that I'm doing in my code: > > 1. Creating a Surface View and getting the Surface from the Surface > Holder from the application layer. > 2. Using JNI, pass the Surface Holder object to your native > application. > 3. Use this object to obtain Surface object > > However, the sufracehandle is null in the JNI. Have anyone faced > similar issues ? Any workarounds or suggestions on how to fix this > issue? > > My code would look like: > > Player.java: > Class Player > { > Surface mSurface; > private SurfaceView surfaceView; > private SurfaceHolder surfaceHolder; > native void play (); > > onCreate () > { > surfaceView = (SurfaceView) > findViewById(R.id.SurfaceViewRendererSurface); > surfaceHolder = surfaceView.getHolder(); > surfaceHolder.addCallback(this); > surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); > /* Populate mSurface object here. */ > mSurface = surfaceHolder.getSurface (); > ...... > play (); > ...... > > } > } > > Player.cpp: > ..... > ..... > struct fields_t { > jfieldID surface; > jfieldID surface_native;}; > > static fields_t fields; > > static sp<Surface> get_surface(JNIEnv* env, jobject thiz) { > Surface* const p = (Surface*)env->GetIntField(thiz, > fields.surface_native); > return sp<Surface>(p); > > } > > jint Java_com_test_Media_Media_play (JNIEnv *env, jobject thiz) > { > sp<Surface> nSurfaceHandle; > jobject surface = env->GetObjectField(thiz, fields.surface); > > if (surface != NULL) { > const sp<Surface>& native_surface = get_surface(env, surface); > nSurfaceHandle = native_surface; > > if (nSurfaceHandle == NULL) > { > LOGE ("ERROR :: Surface Handle NULL"); > > } > } > return 0; > } > > Thanks in advance. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.