Java application only playing selected videos in my computer

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

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

#16 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 - 05:06 PM

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

Tell your IDE to include the .mp4 files in the jar file.

How can this be done? Any solution? Rest assured that I am absolutely interested in learning about your suggestion. That is a given. Thanks
Was This Post Helpful? 0
  • +
  • -

#17 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 27 May 2020 - 05:11 PM

Quote

But how can videos be saved in the same jar file?
I am of course assuming you mean saved by the user. If so, please see my previous comment
Was This Post Helpful? 0
  • +
  • -

#18 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 - 05:11 PM

View Postg00se, on 27 May 2020 - 04:58 PM, said:

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)?


Thank you for the shared insight. I was considering the age group and the fastest way to get the kids to select their preferred video clips already made available to them on the bottons. Is this requirement very challenging to conquer? What do you suggest?
Was This Post Helpful? 0
  • +
  • -

#19 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 27 May 2020 - 05:14 PM

The problem is your use case is vague.
Are you saying you want selection from a narrow range of videos to be possible and for that range to be fixed?

This post has been edited by g00se: 27 May 2020 - 05:15 PM
Reason for edit:: Clarification

Was This Post Helpful? 0
  • +
  • -

#20 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 27 May 2020 - 05:16 PM

Files can be added to a jar file with the jar command with the u (update) option:
jar -uf <JarFileName> <file to add>
Was This Post Helpful? 0
  • +
  • -

#21 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 - 06:30 PM

View Postg00se, on 27 May 2020 - 05:14 PM, said:

The problem is your use case is vague.
Are you saying you want selection from a narrow range of videos to be possible and for that range to be fixed?

Yes! The number of buttons equates to the number of options available to the user (kids). Strictly dependent on the number of buttons. Thanks

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

Quote

But how can videos be saved in the same jar file?
I am of course assuming you mean saved by the user. If so, please see my previous comment


No, I meant saved by me before the user receive the .exe file (cannot be edited). Thanks
Was This Post Helpful? 0
  • +
  • -

#22 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 - 06:36 PM

View PostGodknows, on 28 May 2020 - 01:30 AM, said:

View Postg00se, on 27 May 2020 - 05:14 PM, said:

The problem is your use case is vague.
Are you saying you want selection from a narrow range of videos to be possible and for that range to be fixed?

Yes! The number of buttons equates to the number of options available to the user (kids). Strictly dependent on the number of buttons. Thanks

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

Quote

But how can videos be saved in the same jar file?
I am of course assuming you mean saved by the user. If so, please see my previous comment


No, I meant saved by me before the user receive the .exe file (cannot be edited). Thanks

Was This Post Helpful? 0
  • +
  • -

#23 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 - 02:50 AM

OK. If i were doing something like constructing a grid of buttons, each able to play a video, i would read in a loop using getResource("/videos/" + n + ".mp3") where n is an integer loop index until an exception is thrown (and caught). That way you can easily add further videos later without confining yourself to a fixed number of them. getResourceAsStream can be used as well. See

http://technojeeves....a-with-netbeans
http://technojeeves....va-with-eclipse
Was This Post Helpful? 1
  • +
  • -

#24 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 - 04:17 AM

View Postg00se, on 28 May 2020 - 09:50 AM, said:

OK. If i were doing something like constructing a grid of buttons, each able to play a video, i would read in a loop using getResource("/videos/" + n + ".mp3") where n is an integer loop index until an exception is thrown (and caught). That way you can easily add further videos later without confining yourself to a fixed number of them. getResourceAsStream can be used as well. See

http://technojeeves....a-with-netbeans
http://technojeeves....va-with-eclipse


Thank you for your leading responses. I have gone through the link. But I have done this - putting images using Netbeans GUI in a package. It is also relocatable.

I can also locate the file path of any one of the video in any computer. The challenge is that the absolute path method produces this path with a single backward slash (C:\this\User_A.mp3) instead of the playable (C:\\this\\User_A.mp3). My question concerning this is how do I add the extra slash so that the video becomes playable?

Regarding your effectual tutorial, my other question is how do I make reference to the video file location when the app is being used by another PC. Everything works as planned on my PC alone. But, according to my code description, the application is unable to locate the video files on another PC (though it partially can, the generated file paths need an extra slash to connect the dots). What do you suggest?

View Postg00se, on 28 May 2020 - 09:50 AM, said:

OK. If i were doing something like constructing a grid of buttons, each able to play a video, i would read in a loop using getResource("/videos/" + n + ".mp3") where n is an integer loop index until an exception is thrown (and caught). That way you can easily add further videos later without confining yourself to a fixed number of them. getResourceAsStream can be used as well. See

http://technojeeves....a-with-netbeans
http://technojeeves....va-with-eclipse


Thank you for your leading responses. I have gone through the link. But I have done this - putting images using Netbeans GUI in a package. It is also relocatable.

I can also locate the file path of any one of the video in any computer. The challenge is that the absolute path method produces this path with a single backward slash (C:\this\User_A.mp3) instead of the playable (C:\\this\\User_A.mp3). My question concerning this is how do I add the extra slash so that the video becomes playable?

Regarding your effectual tutorial, my other question is how do I make reference to the video file location when the app is being used by another PC. Everything works as planned on my PC alone. But, according to my code description, the application is unable to locate the video files on another PC (though it partially can, the generated file paths need an extra slash to connect the dots). What do you suggest?
Was This Post Helpful? 0
  • +
  • -

#25 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 - 04:35 AM

Quote

absolute path method produces this path with a single backward slash (C:\this\User_A.mp3) instead of the playable (C:\\this\\User_A.mp3)

The issue of \\ vs \ is only a problem when coding the source for the program. Because a \ is a special character for the compiler, you need to code two of them to tell the compiler that you want a single \ in a String. If you code: String path = "C:\\this\\User_A.mp3"; in the source and print the value of path you will see String only has single \s: C:\this\User_A.mp3
The compiler has changed the \\ to \

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

Was This Post Helpful? 0
  • +
  • -

#26 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 - 04:48 AM

View PostNormR, on 28 May 2020 - 11:35 AM, said:

Quote

absolute path method produces this path with a single backward slash (C:\this\User_A.mp3) instead of the playable (C:\\this\\User_A.mp3)

The issue of \\ vs \ is only a problem when coding the source for the program. Because a \ is a special character for the compiler, you need to code two of them to tell the compiler that you want a single \ in a String. If you code: String path = "C:\\this\\User_A.mp3"; in the source and print the value of path you will see String only has single \s: C:\this\User_A.mp3
The compiler has changed the \\ to \


Thank you for the leading responses. However, I am not coding this path, C:\\this\\User_A.mp3; I am requesting for it from the absolute path method. Can I tell the program to replace \ with \\\\ so that \\ will appear? How will it effect the changes in the content of the file so that I will automatically get double slashes? Thanks
Was This Post Helpful? 0
  • +
  • -

#27 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 - 04:51 AM

Why do you want the String holding a path to contain \\?
What problem do you have if the String has \?
Was This Post Helpful? 0
  • +
  • -

#28 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 - 04:55 AM

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";

This post has been edited by g00se: 28 May 2020 - 05:01 AM
Reason for edit:: typo

Was This Post Helpful? 0
  • +
  • -

#29 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 - 05:00 AM

View PostNormR, on 28 May 2020 - 11:51 AM, said:

Why do you want the String holding a path to contain \\?
What problem do you have if the String has \?


I noticed that that was the difference between the assigned path's string -the one that only works on my PC - and the generated one. When I added an extra slash to the generated string the videos played. Hence the assumption that I need to try out a method that automatically generares double slashes: for use in playing the videos. What do you suggest?
Was This Post Helpful? 0
  • +
  • -

#30 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 - 05:47 AM

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

This post has been edited by NormR: 28 May 2020 - 05:49 AM

Was This Post Helpful? 0
  • +
  • -

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