Use JavaFx Media Player as default player for media files - java

I am developing Media Player in JavaFx and now I want that when I right click on any media (.mp4) file and open with my JAR file that it will start playing. How to get this function work?

I am not a pro in java, but in most programming languages when we open with something, the path is sent as argument.
In java maybe the parameter String[] argsin main method, which is an array, will contain the path to the file you opened with. Then you can use it to open the file.
You can test it easily by printing the array args, and opening the mp4 file with .exe or .jar(not sure)
At end sorry for the confusion but I am at this time unable to test as i am away from any jvm.
If you want it in android then you have to further view intents-filters here
https://developer.android.com/guide/components/intents-filters

Related

opening a file by double clicking

I saw a video tutorial about making a video player in javafx. In that tutorial the path to the video file was set in the program code itself. I searched a lot to find some tutorial to pass the path to the file at runtime by double clicking it, like, we always double click on a video file to open it in windows media player or any other similar program. All the file based programs I come across is setting the path in the code itself. How can I make my program to receive the path to the file at runtime or from the operating system? Can anyone suggest me a good tutorial

Passing string/path arguments on my main program to open image files

I'm trying to make a program similar to Windows Photo Viewer, the program that pops up usually if you double-click an image in Windows. I've already made my own program, however it uses a JFileChooser associated with a button to bring up images to open inside the application itself (Windows photo app doesn't seem to do this).
Question:
How can I make my application handle certain file types when its double-clicked from Windows? My guess would be something along the lines of my main class having a Path/String type argument of the file I want to open, but I'm not sure how to exactly implement that.
What type does Windows pass to a program whenever we open a file? String?
Once my first question is fixed, is there anything special I would need to do to associate my program to image files (when making .exe file or installer)?
Include a java-web-start <association/> tag as a "hint to the JNLP client that it wishes to be registered with the operating system as the primary handler of certain extensions and a certain mime-type." Note that " the <offline-allowed/> element must also be included." A web server is not required and a platform-specific <shortcut/> is optional. The file to open will be a command line parameter.

Get the filepath of the file being accessed by a window using JNA with Java

I am using JNA with Java to find some properties about open windows on a Windows machine desktop. I am trying to find a way to get the file being accessed by an arbitrary windowed application. For instance, say I get information regarding the window of an open pdf document in adobe. I want to be able to get the filepath of the pdf document displayed in the window.
I know about the GetWindowModuleFileName() method, however this gets you the filepath of the executable of the application, i.e. 'javaw.exe'. If you have 'my.pdf' open in adobe, I'd like to get the filepath of this document, i.e. 'C:\...\my.pdf'.
I've done some searching around (on this site and others) and haven't found anything yet on this in particular.
thank you for your time, -Kevin
If you know the process ID, you can get the list of all files currently opened by the process using Handle utility. However, it depends if adobe reader continues to keep the file open or closes it after reading it completely.

Programmatically call default media player in Blackberry?

Like I said, the application has to call the default Blackberry media player.Does anybody know or maybe point in a direction to implement it
Enviroment : Eclipse+BB plugin 4.5
There are two ways to do this.
The first approach would be to use the content handler mechanisms of the device. You'll essentially be forcing the device to deal with a given file in a default manner. For audio files, the default manner would be to launch the media player on the device with the file.
So, for example if you have a file called song.mp3 on the SD card on the device, you would do something like the following (code is from memory, haven't checked it in a while):
Invocation invocation = new Invocation("file:///SDCard/BlackBerry/music/song.mp3");
Registry reg = Registry.getRegistry("net.rim.device.api.content.BlackBerryContentHandler");
reg.invoke(invocation);
The second approach would be to use the content handler in the BlackBerry web browser to, essentially, accomplish the same thing. In the case of a browser, you can use the standard classes related to net.rim.blackberry.api.browser.BrowserSession to launch an instance of a browser with the URL to the music file. The URL can be something on the web, or, as above, it can be a file:// location on the device itself. This will cause the browser to deal with the content, which will essentially launch the music player and play the file.

How do you call the default media player to play a wav file in Java?

How do you call the default media player to play a wav file in Java?
Desktop.getDesktop().open(new File("path/to/file.wav")) ought to do it.
You can also play a wav-file in Java without mediaplayer.
Take a look at this page: AePlayWave.
If you realy want to open a mediaplayer, you can use the rundll utility.
// "file" is the filename of the data file
// ex. myresume.doc
// to start Word if the doc extension is associated with it.
Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file.getAbsolutePath());
This util works only in Windows
go google for edu.stanford.ejalbert.BrowserLauncher - package for OS independent call. It opens file with default program regardless of you run your app on linux, mac or windows... so you don't have to worry about whether user has windows media player or would like better his winamp to play .WAV files...

Categories