Java Question R.Layout and findViewById(R.id.surface_view)

moster67

Expert
Licensed User
Longtime User
I am gradually writing a wrapper for the Vitamio-plugin. See my post here: http://www.b4x.com/forum/additional-libraries-classes-official-updates/19329-vitamiob4a-b4a-wrapper-vitamio-plugin-advanced-videoview-library.html

Most stuff works but I have a problem with setting the video-size. From the sources I am using (link for download: http://files.cnblogs.com/over140/2012/5/Vitamio-Demo2012-5-22.zip) and when compiling the project (make sure to use VideoViewDemo - you can comment out the other project), the resulting app works nicely and in particular change of video-size (double-tapping on screen).

In my own B4A sample-project (see my VitamioB4A post), I can get some results (in Panel long-click event) but it is only the view itself which changes size and not the playing video contrary to the sample-app generated from the sources I am using.

I believe it has something to with the surface_view. In the sources (and the app) which are working, there are two lines as follows:

B4X:
setContentView(R.layout.videoview);
mVideoView  = (VideoView) findViewById(R.id.surface_view);

//for my project, I had to change it into:

vitamioExt = (VideoView) findViewById(R.id.surface_view)

I have not been able to implement above code (my knowledge of Java is very poor) and I believe said code might be the reason why the change of video-size does not work. Maybe it is not possible anyhow to use said code in B4A-wrappers since I believe the xml-layout is only created during compilation although I am not sure. If this is the case, what can I do overcome that problem?

Note: in the API, there is also also an event called "OnVideoSizeChangedListener" but it seems it is not used in the sources I am using so it is probably of no importance.

As mentioned, you can find my eclipse-sources in the other post. If some of you experts would like to take a look and see if there is something obvious which is missing or which I am doing wrong, I would really be grateful. If there is an error or something I have not implemented properly, you will probably find in the wrapper-source (Eclipse). However, maybe I am not using the wrapper correctly in the B4A-project. I am not 100% sure.

In a certain way, I am already pleased with the wrapper-library at is current state but still it would be a pity if I couldn't implement the change of video-size since it is actually working in the other sample-project mentioned above. It would also be another benefit of this library since the standard Android video-view does not support video-sizing (only original size).

Thanks.
 

warwound

Expert
Licensed User
Longtime User
Here's an example of how to access the R Resources class of a B4A application from within a library:

B4X:
String resourceName="surface_view";
int resourceId = BA.applicationContext.getResources().getIdentifier(resourceName, "id", BA.packageName);
vitamioExt = (VideoView) findViewById(resourceId)

Martin.
 

moster67

Expert
Licensed User
Longtime User
Thanks Martin.

I had seen that code earlier on the forum but I was unsure how to implement it.

In either case, I got the video-size problem sorted. The library is OK and doesn't need those two lines of code mentioned in my first post. At the end, the problem was in B4A. I had to remove the view and then re-add it in order to get it working. :sign0161:

Thanks once again for your help.
 

robertogv64

Member
Licensed User
Longtime User
Here's an example of how to access the R Resources class of a B4A application from within a library:

B4X:
String resourceName="surface_view";
int resourceId = BA.applicationContext.getResources().getIdentifier(resourceName, "id", BA.packageName);
vitamioExt = (VideoView) findViewById(resourceId)

Martin.
Hello Martin,

I have seen and tested your code to access R resources in B4A, I have tried it and always return 0.

There is some additional definition that must be made for the implementation of this instruction and to be able to access this resource?
 
Top