Codename One - Video Capture - java

Am using codename one to capture the video and upload it to Vimeo.
But I get errors when I click the button. What am I doing wrong ?
I get below error when the method is called.
I have a camera
java.lang.NullPointerException
at userclasses.StateMachine$1.actionPerformed(StateMachine.java:63)
protected void onMain_Button1Action(Component c, ActionEvent event) {
Capture.captureVideo(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(Capture.hasCamera()){
System.out.println("I have a camera");
}else{
System.out.println("I don't have a camera");
}
try {
String path = (String) evt.getSource();
Log.p("Path->" + path);
Vimeo.MyVimeo(path);
is.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}

The event can be null if the operation is canceled.

You are not meant to select a file, The capture class is for capturing media files from the device. It brings out FileChooser if you are using the emulator, therefore test it on a device and see how it works.

Related

Popup a compulsive window that the user can only interact with by Java Swing

So compulsive window here means like, I currently have interface(1) with a button, I click the button and it gives me a popup. I want this popup to be the only window that the user can interactive, so the user in this case cannot interact with interface(1). Think it like you are saving a Word doc, when you choose the file location to save this Word doc, you cannot modify the content of this Word doc. And that file saving window is what I want.
Currently I have a custom popup:
public class InputPopup {
private int closeflag;
private JFrame popup;
...
public int getCloseflag() {return closeflag;}
public void close(){
System.exit(0);
}
public void run() {
EventQueue.invokeLater(() -> {
try {
popup.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
And this is what I did in the button listener
InputPopup popup = new InputPopup(wordLabel.getText(), description.getText());
popup.run();
int flag = popup.getCloseflag();
while (flag != 1) {
flag = popup.getCloseflag();
}
popup.close();
Of course that does not work. Anyone has any idea on how to achieve that effect?

Playing music in java on threads

I am currently creating virtual drum kit. Kinect is recording my moves and when I hit the virtual drum the program needs to play the sound of this drum. Currently my code to play music looks like that:
void playInstrumentSound(InstrumentModel instrument) {
if (instrument.getMedia() != null) {
new Thread() {
public void run() {
instrument.setPlaying(true);
MediaPlayer player = new MediaPlayer(instrument.getMedia());
player.setVolume(1);
player.play();
try {
Thread.sleep(properties.getSleepLength());
} catch (InterruptedException e) {
e.printStackTrace();
}
instrument.setPlaying(false);
player.dispose();
}
}.start();
}
}
InstrumentModel is my class that contains Media object that is initialized by using pathToSound which is path to .wav file in resources folder:
if (this.pathToSound != null) {
media = new Media(new File(this.pathToSound).toURI().toString());
}
Right now this code doesn't reach my expectations, because if I hit a drum then I can't hit it again for the properties.getSleepLength() value of time (now it is about 200ms). If I don`t make Thread sleep then I don't hear full sound.
For example, if the .wav file duration is 300ms and I make Thread.sleep(300) inside playInstrumentSound() method, then I can hear full sound but I can't play different sound for this 300ms. But if I make Thread.sleep(50) then I can hit it again almost instantly but I hear only 50ms of the .wav file.
I would like to be able to hit the drum almost instantly but also hear full sound of it. How can I reach that? Thanks in advance.
EDIT:
I just got an idea to change order inside playInstrumentSoundMethod:
void playInstrumentSound(InstrumentModel instrument) {
if (instrument.getMedia() != null) {
instrument.setPlaying(true);
MediaPlayer player = new MediaPlayer(instrument.getMedia());
player.setVolume(1);
player.play();
new Thread() {
public void run() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
instrument.setPlaying(false);
}
}.start();
new Thread() {
public void run() {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
e.printStackTrace();
}
player.dispose();
}
}.start();
}
Now it should turn the sound off after 250ms and changes isPlaying flag after 50ms (if isPlaying flag is true then you can't hit a drum again). You think that it might work?

Java - Listen for copy and paste from clipboard

( 1 ) Is there a way to listen for any clipboard updates (including Ctrl+C/X, PrtSc (screenshot) and changes made by other programs) in Java? I have tried this:
Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(new FlavorListener() {
#Override
public void flavorsChanged(FlavorEvent e) {
System.out.println("Copy detected");
}
});
This handles Ctrl+C changes well but doesn't notice changes which are not made by user manually, e.g. by screenshotting software or PrtSc button.
( 2 ) Is there a way to listen for paste actions (Ctrl+V, "paste" button, etc.)? I want something like that (or just with similar functionality):
// ...
#Override
public void prePaste(PasteEvent e) {
System.out.println("Paste detected");
e.cancel(); // reject the paste (so that user's Ctrl+V pastes nothing)
}
// ...
one way to capture when things are pasted into composites is to add a Listener "addKeyListener".
Java 8
KeyAdapter keyAdapter = new KeyAdapter()
{
#Override
public void keyPressed(KeyEvent keyEvent)
{
if(((keyEvent.getModifiers() & InputEvent.CTRL_MASK) != 0) && (keyEvent.getKeyCode() == KeyEvent.VK_V))
{
String text = null;
try
{
text = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);
System.out.println(text);
}
catch(Exception e)
{
e.printStackTrace();
}
keyEvent.consume();
}
}
};
stringTF.addKeyListener(keyAdapter);
for java over version 9 you can use the following condition
if(((keyEvent.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) && (keyEvent.getKeyCode() == KeyEvent.VK_V))
{
// Code ....
}

what's -Dcom.sun.javafx.virtualKeyboard=javafx other values

in JAVAFX i want to use windows virtual keyboard instead of JAVAFX virtual keyboard in touch screen whats the true setting or whats the true value to the property
-Dcom.sun.javafx.virtualKeyboard=javafx
If you want to open windows virtual keyboard when user focus on textfield ,you can do that by call osk.exe from the root:
userInputField.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
String sysroot = System.getenv("SystemRoot");
try {
Process proc = Runtime.getRuntime().exec(sysroot + "/system32/osk.exe");
} catch (IOException ex) {
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
}
}
});

How can i show my panels in the other panes?

Hi this is my problem i cant show the panels into the root panel, im doing a similar chat some like skype but the part that i need to show(messages), its not showed, when i send the message to the users.
Well this is my code to send my message:
btnSend.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
String empty = "";
String sendMessage = txtMensajes.getText();
String[] talkTo_array = lstDisplayBuddys.getSelectionModel().getSelectedItem().toString().split("-");
String talkTo = talkTo_array[talkTo_array.length - 1]+"#mpns.mcm.net.mx";
try{
// CONDITION IF ARE EMPTY THE MESSAGES
if (sendMessage.equals(empty)) {
JOptionPane.showMessageDialog(null, "Add some message");
}
else{
if (talkTo != sendMessage) {
while (true) {
try {
sendMessage(XMPPChatHelper.encodeBase64(sendMessage), talkTo);
System.out.println("send message");
//SHOW MY MESSAGES WHEN I SEND IT
Platform.runLater(()->{
pnContArea.getChildren().addAll(drawSendMessage(sendMessage));
txtMensajes.setText("");
});
} catch (XMPPException e) {
e.printStackTrace();
}
break;
}
ConnectionDBHistorialHelper ConnectionDBHistorialHelper=new ConnectionDBHistorialHelper();
ConnectionDBHistorialHelper.saveMessageSend(sendMessage);
}
}
}catch(Exception e){
}
}
});
and this is the method that draw the image and the text into the other panel:
public StackPane drawSendMessage(String message){
StackPane paneSend=new StackPane();
Platform.runLater(()->{
Text sendMessageText=new Text(message);
ImageView imaSend=new ImageView(HomeController.class.getResource("/image/isend.png").toExternalForm());
paneSend.getChildren().addAll(imaSend,sendMessageText);
paneSend.setAlignment(Pos.BASELINE_LEFT);
});
return paneSend;
}
thnks advanced.
He he it's very easy to do that you only need to initilize the whatever variable in this case all panes with
#FXML private variablePane variable;

Categories

Resources