Log in or register to post comments

Adding Virtual buttons to VideoPlayback

April 27, 2013 - 7:44am #1

Hello,

 

I'm developing an android application in which I want to display different videos OnPressing different virtual buttons.
Now I have both samples (VideoPlayback and VirtualButtons) installed.. How can I add the virtual buttons to VideoPlayback project? 
 
I modified the xml file by adding avirtual button to the marker .. This is done..
but how to combine .cpp and .java files?
 
Appreciate your help!
 

 

Adding Virtual buttons to VideoPlayback

October 17, 2013 - 11:27am #16

alhammadi_am wrote:

Hello,

I'm developing an android application in which I want to display different videos OnPressing different virtual buttons.

Now I have both samples (VideoPlayback and VirtualButtons) installed.. How can I add the virtual buttons to VideoPlayback project? 
 
I modified the xml file by adding avirtual button to the marker .. This is done..
but how to combine .cpp and .java files?
 
Appreciate your help!
 
Hello, How did add virual buttons into the marker in the xml file?
 

 

Adding Virtual buttons to VideoPlayback

July 30, 2013 - 11:16pm #15

I followed your suggestion to modify my code, but it doesn't work.

if (strcmp(trackable.getName(), "chips")==0)
        {
        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                     (const GLvoid*) &steam_engineVerts[0]);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                     (const GLvoid*) &steam_engineNormals[0]);
            glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                     (const GLvoid*) &steam_engineTexCoords[0]);
            glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                     (const GLvoid*) &straightengineVerts[0]);
            glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                     (const GLvoid*) &straightengineNormals[0]);
            glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                     (const GLvoid*) &straightengineTexCoords[0]);
        }
       glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);
 
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
 
        if (strcmp(trackable.getName(), "chips")==0){
        glDisable(GL_CULL_FACE);
        glDrawArrays(GL_TRIANGLES, 0, straightengineNumVerts);
        glDrawArrays(GL_TRIANGLES, 0, steam_engineNumVerts);
        glEnable(GL_CULL_FACE);
        }
 
When i face the camera to "chips" image, it suppose to display two 3D model, one is steam engine, the other one is straight engine. but it doesn't work in reality, it will just crash. Please give me some suggestions. Thank you very much.

 

Adding Virtual buttons to VideoPlayback

July 30, 2013 - 5:45am #14

Yes, it is perfectly possible to render several 3D models in one markers; the relevant code is the OpenGL code that you find in the _renderFrame() method, starting at the line where you see:

result->getPose()

and following lines.

The rest is just about OpenGL programming, so you have the freedom to do whatever you want with it.

 

Adding Virtual buttons to VideoPlayback

July 30, 2013 - 4:55am #13

thank you. I will try it. I have one more question. Is it possible to display more than two 3D model in one marker by using ImageTargets project? And i can control their individually. thank you.

Adding Virtual buttons to VideoPlayback

July 29, 2013 - 11:32pm #12

Glad to hear it works.

To integrate Virtual Buttons into Image Targets there is no general recipe; you need to study the two samples and pick the relevant code from one and bring it into the other...

 

Adding Virtual buttons to VideoPlayback

July 29, 2013 - 9:58pm #11

It works now. Thank you very much. It is really helpful.

If i would like to add virtual buttons into imagetarget project, what kinds of change i need to make?

Adding Virtual buttons to VideoPlayback

July 29, 2013 - 4:50am #10

If you follow the steps in that article, you will see that the Handler has a method called handleMessage:

 ImageTargetsRenderer.mainActivityHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                // put your code here
            }
        };

That's where you need to put your code to show the video url.

Adding Virtual buttons to VideoPlayback

July 29, 2013 - 4:23am #9

I saw the handler method, but i don't get how to use handler method to approach my problem. Coud you explain a little bit?

Adding Virtual buttons to VideoPlayback

July 29, 2013 - 3:17am #8

yes, putting the code in your playVideo() method is correct...

if that still does not fix the issue, try the Handler approach...

 

Adding Virtual buttons to VideoPlayback

July 29, 2013 - 3:03am #7

Thank you for your reply. But it still doesn't work, it has the same error. I used "runOnUIThread()" to modify my code, i don't know why it is still not working.

I add this runOnUiThread into my playVideo function. is it correct? if not, how should i call this thread from c++ file? Thank you.

Adding Virtual buttons to VideoPlayback

July 28, 2013 - 11:54pm #6

One common reason for that error is a threading issue; looking back to your code, you are calling the playVideo() from C++ via JNI (which is technially correct); however, the C++ code from which you are calling seems to be part of the _renderFrame() function, ,eaning that it is called from the OpenGL rendering thread;

this thread is not the same as the main UI thread which updates the GUI; so, your Java code to launch the Intent is actually exeuted from the wrong thread;

you need to move this to the UI thread; you can do this in 2 ways:

using a Handler, as illustrated here:

https://developer.vuforia.com/forum/faq/android-how-can-i-update-my-ui-response-tracking-events

or by using the "runOnUIThread()" method of Android, i.e. modifying your current Java code this way:

this.runOnUiThread(new Runnable() {

        public void run() {
            String url="http://www.youtube.com/watch?v=YVJsZCU6z1A";
            Uri uri=Uri.parse(url);
            Intent i=new Intent(Intent.ACTION_VIEW,uri);
            startActivity(i);
} });

 

Adding Virtual buttons to VideoPlayback

July 28, 2013 - 9:21pm #5

This is the log error display "Fatal Signal 11 (SIGSEGV) at 0x00000004 (code=1), thread 28242 (thread-1585)", but i don't know what this error it is, why this error will occur? Please help, thank you very much.

Adding Virtual buttons to VideoPlayback

July 25, 2013 - 3:17am #4

The code looks correct; however, checking the exact error message in the Logs would help narrow down the problem.

Adding Virtual buttons to VideoPlayback

July 25, 2013 - 2:37am #3

Hi, i try to play a youtube video in virtual button program. But my program is just keeping crush. I don't know why. Please help me to take a look.

VirtualButton.java: ( i create a function in java file, so that i can call in cpp file)

public void playVideo(){
    Uri uri=Uri.parse(url);
    Intent i=new Intent(Intent.ACTION_VIEW,uri);
    startActivity(i);
    }
 
VirtualButton.cpp:
for (int i = 0; i < imageTargetResult->getNumVirtualButtons(); ++i)
        {
            const QCAR::VirtualButtonResult* buttonResult = imageTargetResult->getVirtualButtonResult(i);
            const QCAR::VirtualButton& button = buttonResult->getVirtualButton();
 
            // If the button is pressed, than use this texture:
            if (buttonResult->isPressed())
            {
            if(strcmp(button.getName(),virtualButtonColors[0])==0)
            {
            textureIndex=1;
            jclass activityClass=env->GetObjectClass(obj);
            jmethodID method=env->GetMethodID(activityClass, "playVideo","()V");
            env->CallVoidMethod(obj, method);
            break;
            }
....
}
please tell me what's wrong with my code. thank you very much
 

Adding Virtual buttons to VideoPlayback

April 28, 2013 - 1:12pm #2

Hi, we don't have a tutorial explaining what code needs to be changed to integrate one sample with another;

your best bet is to study the two samples and understand the code; the rest is just about programming.

 

Log in or register to post comments