Gah I meant to say "sp<> and Surface are *internal implementation* details."

On Wed, Jun 8, 2011 at 12:37 PM, Dianne Hackborn <[email protected]>wrote:

> sp<> and Surface are native APIs.  This code will break on various devices.
>
> The only supported way to do this is with the new extended native APIs in
> 2.3.
>
>
> On Tue, Jun 7, 2011 at 7:06 AM, Sandeep Patil <[email protected]
> > wrote:
>
>> Dear frndz,
>>
>> I am facing a problem of being not able to use the surface object
>> obtained from an activity class in the native side. Here is what i am
>> doing,
>>
>> * Getting a SurfaceView object with the help of findviewbyId()
>> function.
>> * Then obtaining its SurfaceHolder by calling getHolder() function of
>> the surfaceView class.
>> * Then adding a callback to the holder, so as to know when the surface
>> is being created and destroyed.
>> * Once i get the callback of onSurfaceCreated(), i am getting the
>> surface object by getSurface() of the SurfaceHolder class and setting
>> it to a (Surface mSUrface = null ) field in the Activity class.
>> * From onSurfaceCreated() itself, I am calling a native function that
>> tries to access the mSurface object and casts it to sp<Surface>.
>>
>> Here is my native function,
>>
>> JNIEXPORT void JNICALL setSurface(JNIEnv* env,jobject thiz)
>> {
>>    jfieldID    surfacefieldID;
>>    jfieldID    surface_native;
>>    Surface* p;
>>    jclass clazz;
>>
>>    clazz = env->FindClass("com/example/SMFMediaPlayer/
>> SecondActivity");
>>    if (clazz == NULL) {
>>        LOGE("Can't find com/example/SMFMediaPlayer/SecondActivity
>> \n");
>>    }
>>
>>    surfacefieldID = env->GetFieldID(clazz, "mSurface", "Landroid/view/
>> Surface;");
>>    if (surfacefieldID == NULL) {
>>        LOGE("Can't find MediaPlayer.mSurface\n");
>>    }
>>
>>    jclass surface = env->FindClass("android/view/Surface");
>>    if (surface == NULL) {
>>        LOGE("Can't find android/view/Surface\n");
>>    }
>>
>>    surface_native = env->GetFieldID(surface, "mSurface", "I");
>>
>>    if (surface_native == NULL) {
>>        LOGE("Can't find Surface fields\n");
>>    }
>>
>>    jobject surfaceobj = env->GetObjectField(thiz,surfacefieldID);
>>    if (surfaceobj != NULL)
>>    {
>>          p = (Surface*) env->GetIntField(surfaceobj, surface_native);
>>
>>         if(p->isValid())
>>         {
>>                const sp<Surface>& native_Surface = sp<Surface>(p);
>>         }
>>    }
>>   .
>>  //There some more code down here
>>
>>
>>
>> }
>>
>>
>>
>>
>> The problem here is that the execution is stopping at the
>> statement,"const sp<Surface>& native_Surface = sp<Surface>(p);".
>>
>> I am not getting what is the mistake.
>>
>> Actually i am using this code create my own media player. So i request
>> to let me know my mistake or an alternative way to access the surface
>> object. And also i need the SurfaceComposerClient object corresponding
>> the surface object.
>>
>> SOmebody help me out.
>>
>> Thanks You
>> Sandeep Patil
>>
>> --
>> 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
>>
>
>
>
> --
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.
>
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  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

Reply via email to