I would like to access my webcam with JMF, create a snapshot, and email it. I have working email code, but every time I try:
CaptureDeviceInfo inf = CaptureDeviceManager.getDevice("vfw:Microsoft WDM Image Capture(Win32):0");
player = Manager.createRealizedPlayer(inf.getLocator());
But I get a nullpointexception error. How to fix it?
This is because your code is not detecting the webcam
you must copy the jmf.properties file to the same directory as your executable jar
you will find the jmf.properties file int the lib folder of your jmf installation.
For me it was C:\Program Files\JMF2.1.1e\lib\jmf.properties
the device name is "Microsoft WDM Image Capture", what you pass to CaptureDeviceManager.getDevice(). the "vfw://0" part is the locator.
see Owen McGovern's example: http://geoffair.net/java/java_sun1.htm. It has working player and working snapshot code.
Related
I am trying to get access to a text file (log.txt) in a directory. All other questions on this topic refer to getting directories from the emulators internal storage.
My file structure is as such
>androidApp
->App
-->Build
-->src
--->game_log
---->log.txt
--->Main
---->(Android app Code further)
Using new File(System.getProperty("user.dir) + "app\\src\\game_log\\log.txt").exists() gets me false.
Another thing I tried was System.getProperty("user.dir") but that yields me /.
Contextwrapper.getPath() gets me the path of the emulators storage.
Is the file structure of Android Studio different or I am using the wrong method to get the file from my project folder?
[Screenshot displaying the downloaded file in a window[][1]1i am not able to access my downloaded file which i opened in a new small window popup using selenium java and also i am not able to find it in downloads folder.
When i click on a download button-->the file gets downloaded with an icon of word in a new small popup browser window-->but it does not move into the downloads folder. Testcase passes but i am not able to validate.In that browser window i am not able to find any elements....only .... tags are displayed.. While doing it in manual way i am able to view it in downloads folder.
Kindly advise me what should be done.
you are coding in java language,
so, use method exists() which will return boolean value.
You must know your Downloaded file name along with exact download path,
String FileName = "YOUR_FILE_NAME";
File tmpDir = new File("C:\Users\a.k\Downloads\"+FileName);
if(tmpDir.exists())
System.out.println("File Downloaded");
System.out.println("File Not Downloaded");
I've been trying to play audio clips through Java and have had trouble using the javafx library. I've placed the sound files in my src folder and tried various ways of accessing them, and yet i get a NullPointerException each time I access them.
Media sound = new Media("file:beep.wav");
MediaPlayer player = new MediaPlayer(sound);
player.play();
Another way i tried to access the file was
File f = new File("beep.wav");
Media sound = new Media(f.toString());
Also tried a few other things. When i do the system.out.print checks all filenames and paths print out correctly
I am running this on Ubuntu (Wily) 15.10, using Eclipse (Kepler) if that may help anyone help me
Appreciate the help!
Do you run your program on text editing programs (NetBeans, Eclipse, etc) or tryingto run jar file?
In first case, try to place your audio file in your project folder. For example: C:/.../NetBeansProjects/MyPRoject/beep.wav , but declare it wihtout any folder names, like this
Something f = new Something("beep.wav"); // Something is not an Object XD
In second case, after clean-building place your audio file in dist folder of your project.
Let me know if it helps.
Yes, I tried that with no success.
I tried using the Clip method (shown below) and found that I encountered a memory error after playing a sound more than 20 times or so. after clearing out as much memory pertaining to the systems clip to fix the error i just decided it may be a driver issue since i was running on (32bit)Lubuntu and had to manually install a few drivers.
clip = AudioSystem.getClip(null);
clip.open(AudioSystem.getAudioInputStream(sound));
clip.start(); //Clip.stop somewhere down the line
I then installed the newest release of (64bit)Ubuntu and the clip method has worked perfectly for me since.
Should I be doing any cleanup when using this method to avoid memory problems, or will external programs take care of that for me?
Thank you for your timely response.
Put all your sound files in a folder called 'sounds'. The folder should be in your project folder at the same level as the src folder. Then call the following method that takes the audio file name as a String argument.
public void playSound (String musicFile){
Media sound = new Media(new File("sounds/" + musicFile).toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(sound);
mediaPlayer.stop();
mediaPlayer.play();
}
playSound("do.wav")
I have a problem with Android internal storage. I have created folder in package root folder calling getDir() and with MODE_WORLD_WRITEABLE because I want camera app to write captured image in this folder. Anyway, I can see that captured image is inside that folder with DDMS.
Problem is that I cannot read that file.
I tried to read file with this code:
File file = context.getDir("images", Context.MODE_WORLD_READABLE);
File image = new File(file, "image.jpeg");
if (image.canRead())
Log.w("read", "can read");
else
Log.w("read", "can't read");
And in LogCat there is only second message (can't read).
I have also tried to create FileInputStream with file name but I receive FileNotFoundException.
Can somebody tell me what I'm doing wrong here?
Thanks in advance
EDIT:
Reading file is correct but only problem is that when cam app is saving image to specified location, permission set by cam app to image file are -rwxrwx---. After changing permissions with
adb (chmod 777 image.jpeg)
I was able to read image. Interesting thing is that cam app is writing images files to sdcard with ----rwxr-x.
Is there any way to change file permission in runtime?
Why not put it in the default photo directory?
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File file = new File(path, "DemoPicture.jpg");
( From: http://developer.android.com/reference/android/os/Environment.html )
See also a more complete example invoking the camera app: http://developer.android.com/training/camera/photobasics.html
Referencing to Android developers you should use openFileOutput() and openFileInput() to work on the internal storage... you are not allowed / not able to make dirs there. Android does it itself.. Those data will be cleared when your application will be deleted.
I am developing a little game where I use some pictures for the sprites etc etc.
It works just fine when I load it from the disc like this
Image image = new Image("C:\\AppleMan.png");
but how can I load it from a foloder within the project. I am using eclipse as IDE and the language is Java :)
I took a screenshot of a sample project so you can see how I have importet the picture
So I want to load the picture from that resource folder like this pseudo code
Image image = getResource("Resources/AppleMan.png");
but that simply doesn't work.
Any help appreciated :)
1) You should add Resources folder to classpath
2) You should locate file absolutely, i.e. "/Resources/AppleMan.png"
P.S.
3) Sorry, also note that getResource returns URL: http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getResource%28java.lang.String
You're passing a relative path when you were passing a absolute path before. Add the path of the Eclipse workspace.
For example, if your workspace is at C:\Workspace, you need to put
Image image = getResource("C:\\Workspace\\HowToGetResources\\Resources\\AppleMan.png");