Android Java Bixolon SPP-R300 Print Image and Bluetooth - java

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.

Related

Parsing logcat output on android phone [duplicate]

I want to get MediaMetadata (song title / artist) from the current playing android audio source for any app (spotify, google play, soundcloud, YouTube, blackplayer, etc) and am trying to use MediaMetadataRetriever.setDatSource
Currently I have a function 'getActiveNotifications' in 'MainActivity.java' that gets called whenever a button is pressed, my code looks like this:
public void getActiveNotifications(View view) {
String temp ="temp";
Log.i("myTag", "Logging active notifications:");
//get data from MediaMetaData somehow? Always displays correct string in Logcat
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
//mmr.setDataSource("CURRENT APP PLAYING MUSIC (googlePlay / Spotify / Soundcloud etc)");
mmr.setDataSource("https://somewebsite.com/somefile.mp3", new HashMap<String,String>());
//extract metadata and save to string
String albumName = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
Log.i("myTag", "done with function. ");
}
Can I use .setDatSource generally for any music app or does it work for files only?
I can see updateMediaMetaData in Logcat printing media metadata of the currently playing song working for both music streaming and file playing apps (see pic)
Am I on the correct track here? Is there a way I can use .getDataSource on streaming / fileplayer apps for whatever the currently playing audio source is?
any help much appreciated, thanks

JavaFX MediaPlayer not showing Album Cover for all my Audio files, even if they have one

I'm trying to create a basic Media Player in JavaFX. I finally made it possible to display the album cover based on the metadata on the file.
However on some songs it doesn't show anything, even if I know that there is an album cover.
Here theres no problem:
However when I select another file it just looks like this:
I swear the only thing I'm changing is the name of the song. Both of the files are formatted in MP3 and have a 500x500 jpg as album cover. The song plays succesfully. Meaning that the file exist. But no album cover
the me variable is the Media which contains the file.
This is the method I'm using to display the album cover in the program:
private void displayAlbumCover (){
// Will start to show a blank CD
File file = new File("src/sample/images/blank_cd.jpeg");
Image image = new Image(file.toURI().toString());
albumCoverView.setImage(image);
// However if an album cover is found in the meta-data it will be displayed
ObservableMap<String,Object> meta_data=me.getMetadata();
meta_data.addListener((MapChangeListener<String, Object>) ch -> {
if(ch.wasAdded()){
String key=ch.getKey();
Object value=ch.getValueAdded();
if (key.equals("image")){
// If there's an album cover in the metadata it will be displayed
albumCoverView.setImage((Image)value);
System.out.println("Found album cover");
}
}
});
}
Okay I've tried debugging, and this is what I get:
The one above is the one that works fine.
But this one does not. Can you see something based on the information, that I gave you?

mediaPlayer.setSpu() not working

Currently I am working on some code based on VLCJ to play video content, which is working pretty fine, but I am struggling hard making the setSpu() method work.
Just to mention, when it comes to load an external subtitle, in a file apart from the video file, it is working fine. The problem appears when I try to play subtitles contained in the media file. (e.g. subs contained into a MKV file).
I read carefully GitHub post "setSpu not working #278", and I think that maybe the problem is that I am not invoking the setSpu() method correctly.
To make it simple, I am trying to make it works on the example "uk.co.caprica.vlcj.test.basic.TestPlayer".
On TestPlayer.java class, I loaded all native vlc required libs and configured the mediaPath, and mediaPlayer, so if I execute the class, the media player is built properly, and the video starts playing.
Now, to try make the subtitle work, I reused the button "subTitlesButton" on "PlayerControlsPanel.java". First of all, as the spu to be set is the ID of the TrackDescription, I added the following code, and executed to get the spuDescriptions list:
subTitlesButton.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
System.out.println(mediaPlayer.getSpuDescriptions());
}
});
When the Sub-titles button is pressed, the following output is get:
spuDescriptions=[TrackDescription[id=-1,description=Deshabilitar], TrackDescription[id=3,description=Pista 1 - [Español]], TrackDescription[id=4,description=Pista 2 - [Inglés]], TrackDescription[id=5,description=Pista 3 - [Español]]]
So, to keep it simple, I just tried to add the following code and execute it:
subTitlesButton.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
System.out.println(mediaPlayer.getSpuDescriptions());
mediaPlayer.setSpu(3); // TrackDescription[id=3,description=Track 1 - [Spanish]]
}
});
The expected resault would be the subtitle "Track 1 - [Spanish]" with ID=3 to appear on screen, but nothing happens. The video goes on and is being played properly, but the sub-title is not shown.
All the other buttons, work fine when you pressed them, you get the expected result (pause, stop, play, fastforward, rewind, and so on)... so I dont get the point on why media.setSpu() is not working there.
Would be much appreciated some help :)
Thanks in advance.
EDITED The exact problem was that all subtitles contained in the media file (video.mkv) were UTF8 text encoded. I tried to re-mount the video.mkv file with mkvmerge, but this program allways converts SRT files to UTF8 text format.
WORKAROUND convert the SRT files to ASS subtitles format. If the video.mkv contains .ASS subtitles format, the subtitles are always loaded properly by VLC and also by vlcj libs.
Thanks a lot in advance for all the help provided.
If this question can be distilled down to how to use external SPU files with non-ASCII characters, you can try this:
Suppose you have some filename for your external SPU file, the filename containing non-ASCII characters, let's call this spuFileName...
Try:
String asciiFileName = new File(spuFileName)
.toURI()
.toASCIIString();
Or:
String asciiFileName = new File(spuFileName)
.toURI()
.toASCIIString()
.replaceFirst("file:/", "file:///");
Then use asciiFileName instead when you specify the SPU file for vlcj.
If I remember correctly, LibVLC requires ASCII strings on its API. This problem can also show itself if you try and play a video with a filename that contains non-ASCII characters (vlcj detects this and handles it automatically).
But I'm not sure if this really is your problem as given the partial log you posted it looks like VLC has indeed detected the SPU tracks correctly.
On the other hand, if this suggestion does actually work, vlcj could be changed to handle this case (an external SPU file) automatically.
When actually selecting SPU for display, whether the SPU are in a separate file or contained within the video itself, the only thing that matters is the id of the SPU track. vlcj passes this id directly to the LibVLC API method. The fact that the track description strings are not being encoded directly does not matter.
In earlier versions of VLC, this id was actually the index of the SPU track - so 0, 1, 2, 3 and so on.
With the current version of VLC (this was changed around February 2013, I think this means VLC 2.1+) this was fixed to use the actual SPU track identifiers.
So depending on your version of VLC, if the track identifiers are not working for you try just passing an index instead.

how can I create a thumbnail of a video url in android?

I have a problem, I can only create thumbnails of local video files but not of a remote url, here is my code:
bmThumbnail = ThumbnailUtils.extractThumbnail(ThumbnailUtils.createVideoThumbnail("http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4", MediaStore.Video.Thumbnails.MINI_KIND), 50, 50);
I hope you can help me,
regards
christian
I suppose there is no easy way to build the thumbnail without actually downloading the video locally.
So if your question is 'Can I get a thumbnail without having to download the full video?', I'd say...no.
Otherwise, once you have downloaded the video locally, then I guess you can perfectly use ThumbnailUtils.createVideoThumbnail(...) by giving the path to the downloaded file.
I also have the same problem - but what can I say from my tests:
The problem occurs only on android >2.3
in android 2.0 -> 2.3 You can use just
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail( videoUrl, MediaStore.Video.Thumbnails.MINI_KIND);
I hope someone explain what change is on android 4. it doesn't work
I have no problem generating thumbnails from remote videos with the following code:
final Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail( videoUrl, MediaStore.Video.Thumbnails.MINI_KIND );
You don't have to wrap an extractThumbnail() call around it

Playing sound on BlackBerry gives an error

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!

Categories

Resources