Hello Java experts, i'm trying to wrap a simple AudioPlayer found here.
The problem i'm having is that i don't understand how to load a xml layout that is found in the res folder, in one of the examples they are loading the buttons, seekbar, etc... layout like this:
My Question is if I use the #AdditionalResources in B4A how can i find and load this layouts?
This is the code i have so far in Java:
When I compile the library and run it in B4A it compiles just fine but it crashes with this error:
I'm assuming it can not find the resources, any ideas on how to fix this?
Thanks all in advanced.
Cheers,
Walter
The problem i'm having is that i don't understand how to load a xml layout that is found in the res folder, in one of the examples they are loading the buttons, seekbar, etc... layout like this:
B4X:
mPlayMedia = findViewById(R.id.play);
mPauseMedia = findViewById(R.id.pause);
mMediaSeekBar = (SeekBar) findViewById(R.id.media_seekbar);
mRunTime = (TextView) findViewById(R.id.run_time);
mTotalTime = (TextView) findViewById(R.id.total_time);
My Question is if I use the #AdditionalResources in B4A how can i find and load this layouts?
This is the code i have so far in Java:
B4X:
public class GenAudioPlayer extends AbsObjectWrapper<AudioWife>{
private static AudioWife audiowife;
private ViewGroup mPlayerContainer;
public void Initialize(BA ba, String uri) throws InstantiationException, IllegalAccessException{
Uri ll = Uri.parse(uri);
BA.Log("Uri parsed: " + ll);
LayoutInflater inflater = (LayoutInflater) ba.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
String resourceName="aw_player";
int resourceId = BA.applicationContext.getResources().getIdentifier(resourceName, "layout", BA.packageName);
BA.Log("resourceId: " + resourceId);
mPlayerContainer.findViewById(resourceId);
AudioWife.getInstance().init(ba.context.getApplicationContext(), ll).useDefaultUi(mPlayerContainer, inflater);
}
}
When I compile the library and run it in B4A it compiles just fine but it crashes with this error:
** Activity (main) Create, isFirst = true **
Uri parsed: /storage/emulated/0/Youtube_Mp3/sin bandera y llegaste tu.mp3
resourceId: 0
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.ViewGroup.findViewById(int)' on a null object reference
at com.genesis.customaudioplayer.GenAudioPlayer.Initialize(GenAudioPlayer.java:34)
at com.genesis.mp3downloader.main._activity_create(main.java:365)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at com.genesis.mp3downloader.main.afterFirstLayout(main.java:100)
at com.genesis.mp3downloader.main.access$100(main.java:17)
at com.genesis.mp3downloader.main$WaitForLayout.run(main.java:78)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.ViewGroup.findViewById(int)' on a null object reference
I'm assuming it can not find the resources, any ideas on how to fix this?
Thanks all in advanced.
Cheers,
Walter