Playing sound on BlackBerry gives an error - java

I'm having trouble getting a short MP3 file to play in a very small app I'm writing to learn how to develop for the BlackBerry.
Because I'm a newbie at BlackBerry development, I've uploaded my Eclipse project for the app to http://stroke.sampablokuper.com/stroke.zip because I don't know if the problem's with my Java programming, or the way I've laid out the resources in my project, or something else.
It's a very small project - only one Java file & three media files - so please help me by seeing if you can run it without errors in the Curve 8520 simulator on your computer. (It's designed for the 8520, because that's the phone a friend of mine has; I don't have a BB myself - yet!)
The idea is that when the user presses/scrolls "down" on the trackball/pad, a sound will be played, but currently instead of the sound, I just get an error message: javax.microedition.media.MediaException .
I've tried to debug this, but as I say, I'm a total newbie to BB development, so I don't really know how to make sense of the information I get from the breakpoints I've set.
Please can you tell me where I've gone wrong?
I really want to finish this before Christmas; please help!
Thanks in advance :)
EDIT: here's the relevant portion of the code, stripped down as much as possible:
public boolean navigationMovement(int dx, int dy, int status, int time) {
if (dx == 0 && dy == 1)// DOWN
{
makeNoise("growl");
}
return true;
}
private void makeNoise(String action) {
if (action == "growl") {
Dialog.alert("GROWL");
try
{
Player p = javax.microedition.media.Manager.createPlayer("growl.mp3");
p.realize();
VolumeControl volume = (VolumeControl)p.getControl("VolumeControl");
volume.setLevel(30);
p.prefetch();
p.start();
}
catch(MediaException me)
{
Dialog.alert(me.toString());
}
catch(IOException ioe)
{
Dialog.alert(ioe.toString());
}
}
invalidate();
}
Further edit I've removed the link to download the project, since the problem did indeed appear to be with the code, and is now solved anyway.

if you have mp3 file on SDCard your URI should be file:///SDCard/<file>.mp3 but if you are playing it from application then getResourceAsStream is the answer

The problem turned out to be that the string passed to the .createPlayer method needs to be a URI.
I tried many variations along the lines file:///growl.mp3 before eventually giving up (if anyone knows the correct URI syntax for pointing to a file within a BlackBerry App, please comment!) and settling on this:
InputStream is = getClass().getResourceAsStream("growl.mp3");
Player p = javax.microedition.media.Manager.createPlayer(is,"audio/mp3");
It's a bit crufty by comparison, but at least it works!

Related

BLE with MiBand 3

This is my first time asking so please forgive if I happen to show mistakes.
Simply put, I want to create app that able to interact with Mi Band 3. The interaction I'm able to make is just reading battery info. What I truly want is enabling the real-time heart rate and steps scan.
What have I done before?
I've seen and tried https://github.com/pangliang/miband-sdk-android . It was actually this library that made me think that enabling heart scan from Android is possible to do. I tried following with my Mi Band 3 but failed: setHeartRateScanListener, startHeartRateScan, getBatteryInfo.
I've seen, cloned, and tampered a little with https://github.com/Freeyourgadget/Gadgetbridge . It is amazing, It can interact with my Mi Band 3, but the problem is Gadgetbridge do not have heart rate scan feature and I kinda overwhelmed with the code.
Of course, I've tried https://developer.android.com/guide/topics/connectivity/bluetooth-le . After reading the Pangliang's and Gadgetbridge's code I did following to do heart rate scan.
First, I know that I should put listener right? So here's the function
public void listenHeartRate() {
BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb")).getCharacteristic(UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb"));
bluetoothGatt.setCharacteristicNotification(characteristic, true);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
descriptor.setValue(new byte[] {0x01, 0x00});
if(!bluetoothGatt.writeDescriptor(descriptor)) {
Log.d(TAG, "tesListenHeartRate: failed");
}
}
And then, I start the scanning with this.
public void startHeartRate() {
Log.d(TAG, "tesHeartRate: start");
BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb")).getCharacteristic(UUID.fromString("00002a39-0000-1000-8000-00805f9b34fb"));
characteristic.setValue(new byte[]{21, 2, 1});
if (!bluetoothGatt.writeCharacteristic(characteristic)) {
Log.d(TAG, "tesStartHeartRate: failed");
}
}
The problem with this is that writeCharacteristic always returning status 3 which means GATT_WRITE_NOT_PERMITTED.
So, where did I go wrong? Thank you very much.
"(...) I nearly gave up, but then realized that I was missing out something. Authentication. Yes, I missed authentication! Thanks to Andrey Nikishaev,
He has explained very well how mi band is being paired and authenticated. That gave me a good head start. And here are the Authentication steps: (...)"
Whole article: https://medium.com/#yogeshojha/i-hacked-xiaomi-miband-3-and-here-is-how-i-did-it-43d68c272391

LibGDX App Hanging on initializGlfw()

I noticed that recently when I run my LibGDX game it takes a good 20 seconds to boot up which is strange because I'm only loading a few resources. I put breakpoints in my main method to pinpoint where the app was getting stuck, and it turns out it's getting stuck when I call this line:
new Lwjgl3Application(new GdxGame(), config);
In the Lwjgl3Application constructor, it is hanging on this method call:
initializeGlfw();
Which looks like this:
static void initializeGlfw() {
if (errorCallback == null) {
Lwjgl3NativesLoader.load();
errorCallback = GLFWErrorCallback.createPrint(System.err);
GLFW.glfwSetErrorCallback(errorCallback);
if (!GLFW.glfwInit()) {
throw new GdxRuntimeException("Unable to initialize GLFW");
}
}
}
In this method it gets stuck on createPrint and GLFW.glfwInit(). The print method looks like this:
public static GLFWErrorCallback createPrint(PrintStream stream) {
return new GLFWErrorCallback() {
private Map<Integer, String> ERROR_CODES = APIUtil.apiClassTokens((field, value) -> 0x10000 < value && value < 0x20000, null, GLFW.class);
#Override
public void invoke(int error, long description) {
String msg = getDescription(description);
stream.printf("[LWJGL] %s error\n", ERROR_CODES.get(error));
stream.println("\tDescription : " + msg);
stream.println("\tStacktrace :");
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
for ( int i = 4; i < stack.length; i++ ) {
stream.print("\t\t");
stream.println(stack[i].toString());
}
}
};
}
All of these methods come from the Lwjgl library. Does anybody know why my app might be getting stuck on these method calls?
I've had the same issue and it seams to be tied to the machine you are on. I made a clean VS15 solution with GLFW and ran it on several different PCs to find that only my desktop had this issue. I also tested the LWJGL binding of GLFW and had the same results.
[EDIT] the wait happens in the glfwInit() call
/* Initialize the library */
if (!glfwInit()) // stuck here
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(1920, 1080, "Hello World", NULL, NULL);
There is one post that I came across an archived post on the openGL forums that mentions an issue similar to this but it's fairly old and might be referring to a slightly different issue.
I can recommend to check that you are excluding your build folder from any antivirus, sometimes they see the generated executables as potential threats and thus might be slow however i dont believe that's your issue.
Sadly the only option that has worked for me was a clean install of windows, though the bug mysteriously stopped manifesting itself when I connected a VR headset and reappeared a couple days later. Hope you have better luck than me and dont have to clean install your OS and if you find a less cumbersome solution be sure to spread the word.

How can I play Video Files using VLCJ and JavaFX?

I'm aware that JavaFX has it's own media player, but I do not know if it can play MP4 files.
Even if it could, I would still prefer to use VLCJ as VLC supports more formats and varieties than I can count in my near-catatonic state.
I've followed the example posted by Caprical in his VLCJ-JavaFX GitHub but it does, well, nothing.
It doesn't error, but it does nothing.
Looking into the code, it seems the issue is in the Timeline event handler:
private final EventHandler<ActionEvent> nextFrame = new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
Memory[] nativeBuffers = mediaPlayerComponent.getMediaPlayer().lock();
if (nativeBuffers != null) { //<-----This is always NULL so everything in the block is skipped . . .
// FIXME there may be more efficient ways to do this...
// Since this is now being called by a specific rendering time, independent of the native video callbacks being
// invoked, some more defensive conditional checks are needed
Memory nativeBuffer = nativeBuffers[0];
if (nativeBuffer != null) {
ByteBuffer byteBuffer = nativeBuffer.getByteBuffer(0, nativeBuffer.size());
BufferFormat bufferFormat = ((DefaultDirectMediaPlayer) mediaPlayerComponent.getMediaPlayer()).getBufferFormat();
if (bufferFormat.getWidth() > 0 && bufferFormat.getHeight() > 0) {
pixelWriter.setPixels(0, 0, bufferFormat.getWidth(), bufferFormat.getHeight(), pixelFormat, byteBuffer, bufferFormat.getPitches()[0]);
}
}
}
mediaPlayerComponent.getMediaPlayer().unlock();
};
};
It's been suggested I get the logs but that will have to wait as I'm slipping into unconsciousness as I make this post (when I return to the land of the living, I will see about what I can do to post some). If there is a better way to make this happen, I'm all for it if someone can direct me there. Thanks...
The vlcj-javafx sample on the Github project works just fine.
You say in your question that vlcj "doesn't error, but it does nothing".
Well, there are two ways to check for errors which you don't show in the code you posted in your question.
The mediaPlayer.playMedia() method returns a boolean to say whether VLC accepted your MRL or not - did you check the return value? Note that even if this method returns true, it does not categorically mean VLC could play your media, but if it returns false it categorically means it could not be played.
You should add a MediaPlayerEventLister to your media player and provide implementations for "playing()" and "error()". These callbacks will be triggered asynchronously - because that's how LibVLC works - only then can you conclude whether vlcj "doesn't error", or "does nothing".
I suspect your media failed to start, probably because of a wrong filename.

Android Java Bixolon SPP-R300 Print Image and Bluetooth

I'm developing application which prints using Bixolon SPP-R300 mobile printer via Bluetooth.
I've managed to make the Bluetooth connection, print Text and do lineFeed but i still don't know how to print images.
For the text i have this working:
returnValue = mBxlService.PrintText("Text Example",
BxlService.BXL_ALIGNMENT_LEFT,
BxlService.BXL_FT_DEFAULT,
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
The mBxlService have a method for image too (mBxlService.PrintImage).
I want to print a image from the drawable folder in the project. Something like drawable/image.png
Someone have worked with this printer or know how to print images with it? There is few information about this, and i'm really trying here.
Other thing is, every time i connect the printer to android a pairing request happens, there is something to bypass that? to do that by code?
This is the printer: Bixolon SPP-R300
Thanks in advance and sorry for my language, English is not my main language.
Take a look at this link (it has a snipped of code to print image)
Android print image using BIXOLON SPP-R300
And here is the how you can get URI to your resource:
how to get an uri of an image resource in android
So, overall code will look something like this:
Uri picturePath = Uri.parse("android.resource://your.package.name/" + R.drawable.image_1);
mBxlService = new BxlService();
mBxlService.Connect();
if (mBxlService.GetStatus() == BxlService.BXL_SUCCESS) {
returnValue = mBxlService.PrintImage(picturePath.toString(),
384,
BxlService.BXL_ALIGNMENT_CENTER,
40);
if (returnValue == BxlService.BXL_SUCCESS) {
returnValue = mBxlService.LineFeed(2);
}
}
Sure, you need to replace "your.package.name" and R.drawable.image_1.
Also, there is a chance that it won't like a path to resources. In such case, I would recommend to spit the image out to SD card and print it from there.

Eclipse Java Memory Error: Heap. Developing in Android with Phonegap.

I have a Android App I have developed, It has been created from a successful ios App that was released and works fine. On one device it works correctly, no errors and does not crash. However on another device (newer, newer version of Android, faster processor) it crashes. Here are the memory errors when it crashes.
The app is designed to take a picture and to then use that picture as the background for a canvas, then a screen shot is taken. I can go through this process once, but then if I repeat the process and take another picture, the application crashes on exit of the camera API for the second time. And displays these errors. The application is Developed in Eclipse using Phonegap and Jquery mobile. I am unsure which parts of my code I should post to help this problem, but please feel free to ask if you feel some may be relevant.
Any help is really appreciated.
Okay, if you review my post on why we run out of memory on PhoneGap Android apps:
http://simonmacdonald.blogspot.ca/2012/07/change-to-camera-code-in-phonegap-190.html
You may find some tips when you use the camera.getPicture() command. Other than that I'm currently working on fixing some of these Camera issues by bringing everything in house instead of firing a camera intent.
You can make such trick.... To set picture as background use...
public void setbg(){
String pathName = Environment.getExternalStorageState() + "scm_pic.jpg";
Resources res = getResources();
Bitmap bitmap = BitmapFactory.decodeFile(pathName);
BitmapDrawable bd = new BitmapDrawable(res, bitmap);
View view = findViewById(R.id.container);
view.setBackgroundDrawable(bd);
}
And then when you don't need this picture or want to #Override onPause methods or to switch another activity use...
private void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
To use it in #Override use for examole...
unbindDrawables(findViewById(R.id.container));
System.gc();
if you use camera means Destination type must in FILE_URL in android. because DATA_URI gives base64 string so it gives out of memory error sometime. First u get URL from camera then Convert base64 format using filesystem concepts...

Categories

Resources