Java application only playing selected videos in my computer

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »

91 Replies - 2966 Views - Last Post: 11 June 2020 - 08:45 AM Rate Topic: -----

#31 Godknows   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 27-May 20

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 07:28 AM

View Postg00se, on 28 May 2020 - 11:55 AM, said:

You're confusing resource paths with file paths. The former are URLs and therefore always have forward slashes. Those are the ones you need to use for your use case. Forget file paths. In fact forget files altogether as the technique i mentioned doesn't use the file system as such, it uses the class loading mechanism.

But as a separate point, for your use elsewhere, you don't actually need to use backslashes for Windows paths in Java. You can use
String path = "C:/a/b/c.txt";


I think I am about to strike gold. Your leading comment here has made me see reasons with @NormR's assertion that files can be saved. I was digging further when I realised that resources folder are used to save .ico, .mp3 files et al.My question now is, can I, after creating the resources folder (per the Netbeans guide), just go to its location in my computer and save the video files there? Is that how one can save video files: for use in distributed applications? Is that how the getresources method work? Or does the getresources get the location of the file on its own, regardless of where it is located in the other PC? If the latter is true, is there need to create a so-called resources folder, seeing that getresources is able to locate the file.

I have generated a code below for use in locating the files. Assuming all things are set. What do you suggest about the possibility of it working?
Thanks.
 try{
URL urla = this.getclass(). getresources("VLC.exe");

URL urlb = this.getclass(). getresources("GVI National Anthem.mp");

 ProcessBuilder pbh = new ProcessBuilder(urla, urlb);   pbh.start();
}

    catch(IOException e){
    e.printStackTrace();
    }

This post has been edited by NormR: 28 May 2020 - 07:54 AM
Reason for edit:: Fixed code tags

Was This Post Helpful? 0
  • +
  • -

#32 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 07:52 AM

Quote

how the getresources method work?

It uses the provided path with the classpath to find the requested resource (file).
One way most people use the getResource methods is to put the resource inside of the jar file. The jar file is on the classpath. That way the program can access and read the file that is included inside the jar file.

I do not think OS programs like VLC will be able to read files that are inside of a jar file. The file would have to be copied out of the jar file to a folder on the PC the code is executing on and the path to that location would be passed to OS programs like VLC.

This post has been edited by NormR: 28 May 2020 - 07:53 AM

Was This Post Helpful? 0
  • +
  • -

#33 Godknows   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 27-May 20

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 07:54 AM

View PostNormR, on 28 May 2020 - 12:47 PM, said:

If you need to code a String with a \, there needs to be two \\s in the String for the compiler to create a String with a single \

If you code a String with a single \, many times the compiler will give an error message: error: illegal escape character


Thank you for your leading comments
I believe I am about to strike gold. I assume you infer that I can get \\ by coding \\\\. What do you feel about the upgraded code below?
//Third attempt

import java.lang.ProcessBuilder;



//Get VLC's absolute path

File check_vlc = new File("vlc.exe");

String absolute_vlc_path = check_vlc.getAbsolutePath();

String new_absolute_vlc_path = absolute_vlc_path.replace("\\", "\\\\");
System.out.println("new_absolute_vlc_path" +new_absolute_vlc_path);



//Get user_mp3's absolute path

File check_user_mp3 = new

File("User_Anthem__2_.mp3");

String absolute_ check_user_mp3 _path = check_user_mp3.getAbsolutePath();

String new_absolute_ check_user_mp3 _path = absolute_ check_user_mp3 _path.replace("\\", "\\\\");
System.out.println("new_absolute_ check_user_mp3_path " + new_absolute_ check_user_mp3 _path);
ProcessBuilder pbh;

pbh = new ProcessBuilder(new_absolute_check_user_mp3 _path, new_absolute_vlc_path);
pbh.start();

This post has been edited by Godknows: 28 May 2020 - 08:02 AM
Reason for edit:: Fixed code tags AGAIN

Was This Post Helpful? 0
  • +
  • -

#34 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 07:56 AM

Please select ALL of the code before pressing the [CODE] button. The code should be between the two code tags. The last posts have had both code tags together and not enclosing the code.
Was This Post Helpful? 0
  • +
  • -

#35 Godknows   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 27-May 20

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 08:03 AM

View PostNormR, on 28 May 2020 - 02:56 PM, said:

Please select ALL of the code before pressing the [CODE] button. The code should be between the two code tags. The last posts have had both code tags together and not enclosing the code.

Thanks for the guide. Done the needful!
Was This Post Helpful? 0
  • +
  • -

#36 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 08:07 AM

Is VLC.exe a standalone program that does not need to be installed? In other words it is contained in one VLC.exe file that can be copied to any other PC and it will work there?
Was This Post Helpful? 0
  • +
  • -

#37 Godknows   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 27-May 20

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 08:13 AM

View PostNormR, on 28 May 2020 - 02:52 PM, said:

Quote

how the getresources method work?

It uses the provided path with the classpath to find the requested resource (file).
One way most people use the getResource methods is to put the resource inside of the jar file. The jar file is on the classpath. That way the program can access and read the file that is included inside the jar file.

I do not think OS programs like VLC will be able to read files that are inside of a jar file. The file would have to be copied out of the jar file to a folder on the PC the code is executing on and the path to that location would be passed to OS programs like VLC.


Oh is there a way I can programmatically load the dll files/native libraries of the VLC so that the user don't need to install VLC in their computer? Thanks
Was This Post Helpful? 0
  • +
  • -

#38 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 08:14 AM

I don't know. Some programs allow just copying of files, some programs require that they be installed.
Was This Post Helpful? 0
  • +
  • -

#39 Godknows   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 27-May 20

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 08:17 AM

View PostNormR, on 28 May 2020 - 03:07 PM, said:

Is VLC.exe a standalone program that does not need to be installed? In other words it is contained in one VLC.exe file that can be copied to any other PC and it will work there?


Thanks for your leading comments. I also want to know. If the upgraded code works (I haven't tried it yet, but will do so in the coming hours), then it will be able to locate and load the .exe file of VLC together with the mp3. What do you suggest?

This post has been edited by Godknows: 28 May 2020 - 08:25 AM

Was This Post Helpful? 0
  • +
  • -

#40 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 08:29 AM

Could your program use the Desktop class? For example these two lines will display a video:
      Desktop dt = Desktop.getDesktop();
      dt.open(new File("E:\\DigitalImages\\_HarbourIsle\\VID_20150523_152220HI_Utility.mp4"));


Was This Post Helpful? 0
  • +
  • -

#41 Godknows   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 27-May 20

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 08:37 AM

View PostNormR, on 28 May 2020 - 03:29 PM, said:

Could your program use the Desktop class? For example these two lines will display a video:
      Desktop dt = Desktop.getDesktop();
      dt.open(new File("E:\\DigitalImages\\_HarbourIsle\\VID_20150523_152220HI_Utility.mp4"));



Yes I could adopt this new style. But how will the videos be saved in the E-drive unilaterally by the application package? Thanks

This post has been edited by Godknows: 28 May 2020 - 08:38 AM

Was This Post Helpful? 0
  • +
  • -

#42 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 08:42 AM

Here is a possible solution:
include the video files in the jar file
when the code is executed, it copies the video file from the jar file to a user's disk;
after the file is copied, the program uses the path to where the file was copied in the Desktop open() method call.

This post has been edited by NormR: 28 May 2020 - 08:42 AM

Was This Post Helpful? 0
  • +
  • -

#43 Godknows   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 27-May 20

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 08:52 AM

View PostNormR, on 28 May 2020 - 03:42 PM, said:

Here is a possible solution:
include the video files in the jar file
when the code is executed, it copies the video file from the jar file to a user's disk;
after the file is copied, the program uses the path to where the file was copied in the Desktop open() method call.


Thank you for your leading comments. I really look forward to finishing off this challenging stage. Regarding your latest comment, do you have an example that I could study?

How do I save the video files in the jar file? Is this done by physically loading the resources folder (per Netbeans guide) with the video files?

Afterward, am I to use get resources method, to get the video's full file path (provided it will contain double slashes) and then pass the corresponding string to the Desktop method: for use in playing the video? Is this how to go about it? Thanks
Was This Post Helpful? 0
  • +
  • -

#44 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 09:03 AM

Quote

How do I save the video files in the jar file?

I do not know how to make your IDE do it.
I add files to a jar file with the jar command and u option that I posted in an earlier post.

A possible solution again:
store video files in the jar file
when executing the code - use getResource method to access file in the jar file; copy the file out of the jar file to a folder on the user's PC; build a File object with the address the file was moved to;
use the Desktop open method to open the file that was copied to the user's PC.

Forget about changing a \ in the path to \\


A later optimization would be to check if the file is already in the folder where it would be copied and use that version instead of copying the file there.

This post has been edited by NormR: 28 May 2020 - 09:04 AM

Was This Post Helpful? 0
  • +
  • -

#45 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3698
  • View blog
  • Posts: 16,952
  • Joined: 20-September 08

Re: Java application only playing selected videos in my computer

Posted 28 May 2020 - 09:19 AM

We're going around in circles. I asked you very specifically what your use case was and made a recommendation based on that use case. You're now talking about saving files (and to me that means the user saving files)
You're making the mistake of not concentrating on what the user is meant to be doing with your program. You should be framing your questions in relations to that, not on what you think you need to be doing.
Was This Post Helpful? 0
  • +
  • -

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »