Sign in Join

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

Mailing lists / fpc-pascal / 2019-08

how to convert JNByteBuffer variable type to type usable by fw.write

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Mgr. Janusz Chmiel

Please, does somebody of us know how to write file by using binary mode and writing data from The variable which have JNByteBuffer variable type? What do I had to do so I would be able to write data to The output file in binary mode from The variable which have JNByteBuffer variable type? Thank you very very much for yours answers.
I Am using fpcJVM Android target. Unfortunately, fw.write expect Jlstring. Buffer is live \MP3 stream which is automatically loaded by bass.so to The device from The Internet. I want to create record function to record live stream and listen it simultaneously at The same time. So I do not want to use HTTP or other special library to open next standalone media stream to allocate new Internet bandwidth. Do you think, that is it possible or I can not create recording feature to simply? Many of us may be think, why I Am doing my best to develop my own personal little apps by using Pascal and Android. There are so many many players on Google Play. I give you The answer. Professional apps such as Audials, which support recording feature are full of amazing features. I can not tell negative word about it. But many functions have one disadvantage for Me as visually impaired with no buttons, many GUI controls and orientation inside so complex app is not easy. This is The reason why I do my best to develop my own little radio player and recorder from scratch. And I have next important reason. It is very remarkable opportunity to learn object oriented programming, Android API calls, .so libraryes calls and other. By The way. I have never found other solution than units for FPCJVM Android target, which would allow Me to develop GUI with no need to specify object coordinates and positions by using Pixel or other values. I do not know about Java Android library which would allow Me to create buttons, combo boxes and other elements with no depend on .xml files which contain position values and there is other problem. Even if some Java language commands can display short warning or other think, there is important Czech characters encoding problem. There is no free Lazarus compatible library for Windows, which can be really be used without typing numbers to specify object values. VCL have been created for Delphi and I do not know about legal and opensource alternative to VCL for Lazarus for Windows.
So I have decided to program some simple apps for Android. GUI is acceptable by sighted users. Sure, may be, that it will be never so nice like GUI, which uses Gradle themes and special tricks supported by Android studio or Kotlin language. But for Me is very important The fact, that GUI can be used not only with screen readers, but it can be used by sighted users and I can program without assistance of sighted person, who would help Me to tailor GUI by using Mouse and some IDE preview feature while developing GUI.
Next factor. FPCJVM compiler enable Pascal programmer to create professional apps. It is possible to call .jar libraryes without embedded .so libraryes or with embedded ones. Very advanced Pascal programmer can even create .so library by using ARM machine code compiler target and call those functions from FPCJVM based source code. If somebody will improve The quality of javapp.jar, so it will not bother because of swing appled when using it from Windows and when generating Android import header files, it will be possible to use not only newer and newer Android APIS. But it also would be possible to use complex projects such as Exoplayer from Google, if somebody would be able to compile standalone Exoplayer library without demo apps to standalone .jar library and if javapp.jar will be able to create usable import headers for it, it will be next multimedia framework for FPCJVM Android developers. Since Exoplayer support audio and video, it do not depend on native code .so libraryes, it is complex app compiled to classes. The question is, if The parts of Exoplayer code have not been developed by using Kotlin. If so, may be, that creating new tool to generate Pascal import headers from Classes, which have been generated by Kotlin compiler would be very very complex task. Thank you very very much for yours answer on my question.

Reply by email

Jonas Maebe
to Mgr. Janusz Chmiel
Mgr. Janusz Chmiel wrote
Please, does somebody of us know how to write file by using binary mode and writing data from The variable which have JNByteBuffer variable type?

Here is a Java example on how to do it. You need to use java.io.FileOutputStream (JIFileOutputStream in FPC):

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class Main {
   public static void main(String[] args) throws Exception {
     String fromFileName = "from.txt";
     String toFileName = "to.txt";
     FileChannel in = new FileInputStream(fromFileName).getChannel();
     FileChannel out = new FileOutputStream(toFileName).getChannel();
     ByteBuffer buff = ByteBuffer.allocateDirect(32 * 1024);
     while (in.read(buff) > 0) {
       buff.flip();
       out.write(buff);
       buff.clear();
     }
     in.close();
     out.close();
   }
}

(reproduced from
http://www.java2s.com/Code/Java/File-Input-Output/WritewithByteBuffer.htm )

Jonas

Reply by email

Mgr. Janusz Chmiel
to Jonas Maebe

Thank you very much for yours kind acces to my plea. The question is, if compiled Android app by using FPCJVM Android target mode will be able to communicate with .so library with bass.so which will receive The stream from The internet and record received live stream input and store it to The phone flash storage. If it will not crash, bbecause I will not be able to use Java multi threading mode. What do you think?
The author of bass library for Android have confirmed Me, that I can really record The content of variable from downloadproc. The only condition is, that buffer must have non zero lenght. So my way is good. I will try to analyse deeply Android APIS to call methods, which Java programmers uses by mporting .jar libraryes.

Reply by email