Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-08

PPCJVM Android target and bass library function call issue

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mgr. Janusz Chmiel

I Am very sad, that I do not know, how to correctly call The following function from bass.so when running apps produced by FPCJVM Android target mode.
    class function BASS_StreamCreateURL(para1: JLString; para2: jint; para3: jint; para4: CUBBASS.InnerDOWNLOADPROC; para5: JLObject): jint; static; overload;
Because build in Android Mediaplayer API are very slow when opening 128 KB/S MP3 live streams even on fast WIFI sites.
So it is really necessary to use bass.so, since it load data very fast and allocates much more less RAM.
But problem is, that there is no easy solution to call bass.so library and native libraryes in general. Believe Me, simply using external keyword or other command to load library is not enough. It is necessary to pack .so library inside .jar archive. And this archive must also contain compiled Java classes.

My issue is, that I do not know, how to call this function correctly. Sure, I must initialise bass library first by The following line. bass.BASS_Init(-1, 44100, 0);
bass.BASS_StreamCreateURL('http://icecast8.play.cz/cro1-128.mp3', 0,0,sta,h);

But powerful Dex creator do not like my approach with JLobject. I have simply declared h as JLobject by using var command. And this is very probably non sense for DEX creator. COmpiler do not assigned my wrong behaviour as bug, but DEX converter yes. And this is significant warning, that I AM doing something wrong. Here is The complete source code.
I Am working with Pandroid from MR  Cvijanovic. He is really professional and without his support, I could never know PPCJVM and Android API functions so much.
unit Test1;

{$mode objfpc}{$H+}
{$modeswitch unicodestrings}
{$namespace zeljus.com.test1}
interface
uses androidr15, Rjava, AActivity, StdCtrls, ZCBass;
type
   MainActivity = class(Activity)
   public
     procedure onCreate(savedInstanceState: AOBundle); override;
   public
     bass: CUBBASS;
sta: CUBBASS.InnerDOWNLOADPROC;
   end;
implementation
procedure MainActivity.onCreate(savedInstanceState: AOBundle);
var
   layout : AWLinearLayout;
h : JLObject;
begin
   inherited onCreate(savedInstanceState);
   layout:= AWLinearLayout.Create(Self);
   layout.setOrientation(AWLinearLayout.VERTICAL);
   bass:= CUBBASS.create();
bass.BASS_Init(-1, 44100, 0);
bass.BASS_StreamCreateURL('http://icecast8.play.cz/cro1-128.mp3',
0,0,sta,h);
   setContentView(layout);
end;
end.

Reply by email

Jonas Maebe
to Mgr. Janusz Chmiel
Mgr. Janusz Chmiel wrote 6 lines
I Am very sad, that I do not know, how to correctly call The following function from bass.so when running apps produced by FPCJVM Android target mode.     class function BASS_StreamCreateURL(para1: JLString; para2: jint; para3: jint; para4: CUBBASS.InnerDOWNLOADPROC; para5: JLObject): jint; static; overload;

Where does this declaration come from? Do you have an existing Java wrapper for libbass, and then generated the headers for it using javapp? Or are you trying to directly call functions in libbass.so using manually created signatures? The latter will never work, because FPC does not know the "native" modifier for Java methods. Additionally, such an existing Java wrapper would also ensure that all your parameter types are correct.

Jonas

Reply by email

Mgr. Janusz Chmiel
to Jonas Maebe

Dear MR Maebe,
    You are always ready to help Me efficiently. I have special .jar file with compiled java .class files, inc and .pas file and bass.so is build inside .jar file. So I think, that it should work. Line
  bass:= CUBBASS.create();
bass.BASS_Init(-1, 44100, 0);
Cause no problems. Since compiler generate classes and dex converter create .dex file with no issues. App also do not produce crash after compiling it and after run it on Android devices.
The question is if
  bass:= CUBBASS.create();
bass.BASS_Init(-1, 44100, 0);
Can really call data from .so library, or it is code which actually do not do useful thinks.
The positive of Pandroid bundle is that Mr Cvijanovic and his cooperator have included special rjava.pas module and other stuff, so all Android API functions can be used. It is even possible to call .jar libraryes, which have been previously compiled by Javac. He had used many examples. The issue is, that Jlobject parameter is abstract and I do not know, what it can mean.
I have spent many many time to find The cause of The issue. The reason, why I work with Pandroid is The fact, that it is really The only one solution, which fully support PPCJVM Android target, all API calls are working including Mediaplayer interface, it is even possible to call .jar libraries which do not include .so library and call methods in it such as mysql.jar.
I think, that Pandroid is revolutionary project, because it contain also many useful units, Jar libraries support, Android API calls support and calling .so native libraryes inside .ajar files support. I have used FreeVCL, but I have got in serious troubles, because Android API calls did not creator could not generate
classes, if I have wanted to call APi function from AndroidR15.inc or from other units.
And my main reason, why I do not simple use Lamw and Lamwplayer is, that only when I use Pandroid units, I can create GUI really myself with no need to be sad, that I must specify object position values for every object. Sure, some people could tell Me, that GUI is not attractive. But for Me as visually impaired with no sight at all, it is revolutionary approach. Because I could never create even complex GUI with many elements. And compiled apps which do not depend on WEBview will always allocate much less RAM than apps, which uses Webview. Or if Javascript run inside browser process. This is The reason why I do not want to switch to Pas2js. But I Am not so clever to deeply understand how to call some functions. Even Java example for Bass library did not helped Me too much. Net radio example build inside bass for ANdroid official .zip archive. Except line
bass.BASS_Init(-1, 44100, 0);
But it can not play live stream it is too few for now. Thank you very much for yours patience. The reason why I want to use my own little Internet radio player is The fact, that GUI is simple, many other radio apps are full of functions and of many buttons. I want to simple pause, play or stop. If I want to record, I can use Audials for this purpose. But The freedom to do  something which containing simple GUI is really very positive feeling for Me.

Reply by email

Jean SUZINEAU
to Mgr. Janusz Chmiel

Le 11/08/2019 à 11:43, Mgr. Janusz Chmiel a écrit :

Thank you very much for yours patience. The reason why I want to use my own little Internet radio player is The fact, that GUI is simple, many other radio apps are full of functions and of many buttons. I want to simple pause, play or stop.

I were wondering if a Raspberry Pi could be useful for you. Sure, the hardware part would be more difficult for you, and you may need an external battery, but it's easier to program than Android. Freepascal and Lazarus  can run  directly on it. I think that you can even make buttons with a single wire, it's called something like capacitive sensor. I made an electronic bagpipe with an arduino with split pins (attaches parisiennes) as keys. Each split pin is connected to the arduino through a single wire. when you touch the split pin, it changes its capacitance, and this can be detected by program.

Reply by email

Mgr. Janusz Chmiel
to Jean SUZINEAU

Yes, Raspberry Pi  is very interesting device. It is possible to run Linux distributions by using it, it have several USB ports, BLuetooth. In fact, here is a solution for Android, but it is interpreter language. RFO Basic. If user uses Gw library, which uses Basic commands in conjunction with Javascript, Webview Android system app, which is responsible to interpret WEB content can play live radio, video and it is even possible to create GUI without using numbers. But.
Webview must create his own little GUi, his own player, to user must press button for twice. For one time from main app GUI, for second time when WEBview opens player.
I have found out, that if I would like to develop GUI by using Pascal language for Android, The best solution is really Pandroid. Because objects can be created. Sure. Every button, or other object must be declared at The begin, then some lines of code must be added at The other part of .pas source or .lpr source code.
Thank you very much for yours advice and for yours time. .

Reply by email