Java application only playing selected videos in my computer

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

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

#1 Godknows   User is offline

  • New D.I.C Head

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

Java application only playing selected videos in my computer

Posted 27 May 2020 - 02:02 PM

I recently developed a software (intended for Desktop applications) using the Swing tools of Netbeans. The challenge I am having is that my application works as expected only on my PC. When a particular button is pressed a corresponding video is played (using vlc).

However, when I distribute the application (having used launch4j to convert from .jar to .exe) to other PCs the video portion does not play. I know it is because I specified where the video is located in my PC. But I want to learn how to do it differently - to make it play in other PCs. Below is the code that I am currently using to play specific videos (without using JChooser). I also tried using file paths to be able to locate the absolute file paths of the respective files. The pressing challenge, though, is the generated single backward slash instead of double slashes. This is preventing me from using the self-generated file paths. Can I sort the letters and add an extra slash every time each single flash appear. Then afterward combine this and generate the file paths? What do you suggest can be done?

The code section:

    try{
ProcessBuilder pbh = new ProcessBuilder("C:\\Program Files (x86)\\VLC\\vlc.exe", "C:\\Users\\INJESUSNAME\\Documents\\NetBeansProjects\\GESVI_1_1\\dist\\JECE\\GVI National Anthem.mp3");

    pbh.start();
}

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

//Second attempt
    import java.lang.ProcessBuilder;

     //Get VLC's absolute path
    File check_vlc = new File("vlc.exe");
    String absolute_vlc_path = 
    check_vlc.getAbsolutePath();
    System.out.println("absolute_vlc_path" 
    +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();
    System.out.println("absolute_ check_user_mp3 
    _path " + absolute_ check_user_mp3 _path);
    ProcessBuilder pbh;
    pbh = new ProcessBuilder(absolute_ 
    check_user_mp3 _path, absolute_vlc_path);
    pbh.start();
:code:

This post has been edited by modi123_1: 27 May 2020 - 02:04 PM
Reason for edit:: In the future please use the [code] tags in the editor.


Is This A Good Question/Topic? 0
  • +

Replies To: Java application only playing selected videos in my computer

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15743
  • View blog
  • Posts: 63,068
  • Joined: 12-June 08

Re: Java application only playing selected videos in my computer

Posted 27 May 2020 - 02:35 PM

Most likely this is a two part issue. One is, by default, most other people will not have direct access to files on your PC. By default most of that is locked out from external access.

If you had a common directory on a shared network you could see about using that as a perma link, but even then that's a little iffy.

Alternatives would be to have the files move with the app, install next to the app, and reference that.

Then there's hosting them somewhere online that could be hit with a connection.

Then the far-far flung idea is adding them as some sort of resource.. but that's a little foggy in my current java knowledge.
Was This Post Helpful? 0
  • +
  • -

#3 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 27 May 2020 - 02:48 PM

View Postmodi123_1, on 27 May 2020 - 02:35 PM, said:

Most likely this is a two part issue. One is, by default, most other people will not have direct access to files on your PC. By default most of that is locked out from external access.

If you had a common directory on a shared network you could see about using that as a perma link, but even then that's a little iffy.

Alternatives would be to have the files move with the app, install next to the app, and reference that.

Then there's hosting them somewhere online that could be hit with a connection.

Then the far-far flung idea is adding them as some sort of resource.. but that's a little foggy in my current java knowledge.


Thank you for your response. However, it is meant to work offline. And the application is also meant to be used by 4 years' old users (approximately). That was why I added a separate image on each button. This means a child can from the image on each botton select her preferred video to watch (by clicking it). I am still optimistic about getting useful suggestions.
Was This Post Helpful? 0
  • +
  • -

#4 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 834
  • View blog
  • Posts: 6,402
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 27 May 2020 - 02:50 PM

Is the total size of the images small enough that they could all go into the jar file?
Was This Post Helpful? 0
  • +
  • -

#5 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 27 May 2020 - 03:00 PM

View PostGodknows, on 27 May 2020 - 02:48 PM, said:

View Postmodi123_1, on 27 May 2020 - 02:35 PM, said:

Most likely this is a two part issue. One is, by default, most other people will not have direct access to files on your PC. By default most of that is locked out from external access.

If you had a common directory on a shared network you could see about using that as a perma link, but even then that's a little iffy.

Alternatives would be to have the files move with the app, install next to the app, and reference that.

Then there's hosting them somewhere online that could be hit with a connection.

Then the far-far flung idea is adding them as some sort of resource.. but that's a little foggy in my current java knowledge.


Thank you for your response. However, it is meant to work offline. And the application is also meant to be used by 4 years' old users (approximately). That was why I added a separate image on each button. This means a child can from the image on each botton select her preferred video to watch (by clicking it). I am still optimistic about getting useful suggestions.


Moreover, I actually attached the video files to the app. That is why I needed advice on how to properly reference each of them. According to the code I uploaded, I am able to accurately reference each of them in my PC. I needed to be able to reference them when in use by another PC. This was why I thought about the absolute file paths aspect. But that led me needing to attach an additional
Slash to the ones generated. How do I add this other slash? What do you suggest?

View PostNormR, on 27 May 2020 - 02:50 PM, said:

Is the total size of the images small enough that they could all go into the jar file?


Thank you for your response. Yes I was able to attach each image to the Java package in Netbeans so that they would be referenced internally. Hence no qualms with images. The main challenge is referencing each botton with the corresponding videos. In other words, botton A, when clicked, pop out a video that is displayed using VLC. See attached code.
Was This Post Helpful? 0
  • +
  • -

#6 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 834
  • View blog
  • Posts: 6,402
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 27 May 2020 - 03:14 PM

Look at how to use the Class class's getResource or getResourceAsStream methods for how to access files that are contained inside of the jar file.
Was This Post Helpful? 0
  • +
  • -

#7 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 27 May 2020 - 03:21 PM

View PostNormR, on 27 May 2020 - 03:14 PM, said:

Look at how to use the Class class's getResource or getResourceAsStream methods for how to access files that are contained inside of the jar file.


Hmm. This is quite a different approach too. But the challenge is that these video files are not stored inside the jar file. I include them in the folder that contain the jar files. Only images were stored inside the jar file and I don't have a challenge using the images at the minute. I don't think one is able to store videos inside the jar file. Or exactly how do you mean? Thanks.
Was This Post Helpful? 0
  • +
  • -

#8 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 834
  • View blog
  • Posts: 6,402
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 27 May 2020 - 03:41 PM

Quote

able to store videos inside the jar file

Yes, any file can be stored inside of a jar file. The problem is accessing the contents of the jar file by Win10 programs. The files could be copied out of the jar file to the user's folder and accessed by the OS's programs there,
Was This Post Helpful? 0
  • +
  • -

#9 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 27 May 2020 - 03:57 PM

View PostNormR, on 27 May 2020 - 03:41 PM, said:

Quote

able to store videos inside the jar file

Yes, any file can be stored inside of a jar file. The problem is accessing the contents of the jar file by Win10 programs. The files could be copied out of the jar file to the user's folder and accessed by the OS's programs there,


Hmm. I am having a feeling that I am getting closer to the solution. I know how to store images in the jar file. How are videos stored in the same jar file? Also, seeing that the application will be used by many users (1000+), do you think there could be another way to get it ready for use as soon as they each receive thw application? Without me having to yank out files (this files must have been converted to .exe though). Thanks
Was This Post Helpful? 0
  • +
  • -

#10 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 834
  • View blog
  • Posts: 6,402
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 27 May 2020 - 04:04 PM

Quote

How are videos stored in the same jar file

Any file can be stored in a jar file.
Was This Post Helpful? 0
  • +
  • -

#11 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 27 May 2020 - 04:15 PM

View PostNormR, on 27 May 2020 - 04:04 PM, said:

Quote

How are videos stored in the same jar file

Any file can be stored in a jar file.


I celebrate your leading responses. The way I saved the image was by right-clicking on the project, head to new --> package and was able to create a Java package as a result. Thereafter, I clicked on the icon ellipsis on the jlabel and selected "import to project". That way the image was saved in the created package. I can load the jar file and am sure that the pictures will not go awol at any time. But how can videos be saved in the same jar file? Rest assured that I want to learn how this is done. Hopefully I will be able to point to the video in the code as a result. Thanks
Was This Post Helpful? 0
  • +
  • -

#12 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 834
  • View blog
  • Posts: 6,402
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 27 May 2020 - 04:37 PM

Your problem seems to be with how to use your IDE. I do not use an IDE like the one you are using and don't know how to make it add files to a jar file. I use the jar command that comes with the JDK to build my jar file.
What is extension of the video file? Is it something like .mp4?
Was This Post Helpful? 0
  • +
  • -

#13 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 27 May 2020 - 04:55 PM

View PostNormR, on 27 May 2020 - 04:37 PM, said:

Your problem seems to be with how to use your IDE. I do not use an IDE like the one you are using and don't know how to make it add files to a jar file. I use the jar command that comes with the JDK to build my jar file.
What is extension of the video file? Is it something like .mp4?


I use Netbeans and yes, .mp4 for the videos, while I use .mp3 for audio files. Thanks
Was This Post Helpful? 0
  • +
  • -

#14 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3702
  • View blog
  • Posts: 16,962
  • Joined: 20-September 08

Re: Java application only playing selected videos in my computer

Posted 27 May 2020 - 04:58 PM

Quote

But how can videos be saved in the same jar file? Rest assured that I want to learn how this is done.

They can't. The jar file approach is read-only.

Unless you have a special reason for restricting your users, why would you not want to use a file chooser (and a standard save dialog)?
Was This Post Helpful? 0
  • +
  • -

#15 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 834
  • View blog
  • Posts: 6,402
  • Joined: 25-December 13

Re: Java application only playing selected videos in my computer

Posted 27 May 2020 - 05:02 PM

Tell your IDE to include the .mp4 files in the jar file.
Was This Post Helpful? 0
  • +
  • -

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