Your code is accessing a private API, which means that your app will likely break in a future version of Android. DO NOT DO THIS :)
On Thu, Mar 18, 2010 at 12:53 PM, Sandy <[email protected]> wrote: > 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 <[email protected]> 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 [email protected] > To unsubscribe from this group, send email to > [email protected] > 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. > -- Romain Guy Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them -- 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] 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.

