jack turret

Greenhorn
+ Follow
since Dec 22, 2019
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by jack turret



Hi again,

So far I adapted the code in my new Maven project. I now boot again to the mainScreen. You had asked me why I collected the video name and png name in two different arrays. THe reason is that I wanted to add an new ImageView whenever the names of a png and mp4 equalled each other.

I wanted to run your code to see how it works but right now I have one problem, I wanted the code to run in the intialize so it would init the thumbnails at scene switching, as a parameter for the pane I had given my anchorpane in the coresponding screen, but which Parameter should I give to collection? I never worked until now with collections so I dont really know how it works..
Here is the latest code;

3 years ago

Stephan van Hulst wrote:It looks like you're completely confused about the lifecycle of an FXML controller.

A controller is created by JavaFX when the FXMLLoader loads the FXML of the user interface that is controlled by the controller. It goes like this:

  • User calls FXMLLoader.load() for a given user interface FXML definition.
  • The loader reads the FXML and determines the class of the controller that will control the user interface.
  • The loader creates an instance of the controller class and calls its constructor.
  • The loader creates instances of all the JavaFX components needed in the user interface.
  • Components of the user interface are injected into fields of the controller instance that are annotated with @FXML.
  • After all components are done being created and injected into the controller, the loader calls the controller's initialize() method.
  • Execution returns to the method that called FXMLLoader.load(). This method now can access both the user interface and the controller associated with it.

  • With this in mind, here's why your code is not working:

    In VideoSelectionController, when you click on an image, you use FXMLLoader to create a new user interface, but you completely ignore its associated controller instance and instead create your own manually. You must never create your own controller instances, because they won't be associated with a user interface. Your calls to videoController.setMedia() and videoController.videoPlay() won't do anything because the controller doesn't actually control anything.

    Another thing: Why are you loading another instance of the VideoSelectionController in your VideoPlayerController and then ignore it? I don't see what business the video player has with the video selector when it's supposed to play a video, so you can probably remove all of that code.

    Your videolLoop() code is a bit messy and it is poorly named. It looks like you're trying to match the file names of a video and an image from two different arrays. Why? Do you ever have a case where one array contains different file names than another (ignoring file name extension)? I would just use a single collection that contains the file names without extension and then construct the paths of both the image and the video from that. Also, if the resources (not ressources) are packaged with your application and should not be overwritable after the application has been installed on a client system, you really should be using resource paths and not file paths. It looks like you're not using Maven to build your application. Why not?

    If you use Maven, your source code files would be under src/main/java and you could put your FXML under src/main/resources/view and your images under src/main/resources/images, etc. The code to initialize your thumbnails would then look something like this:




    Hey thanks for the long explanation, I think I will start from scratch a project this time with maven and then try to understand the lifecycle of JavaFX and your code and implement it. Thanks for the long and detailed explanation. This forum and community is really good with helping each other out haha, I will report back how it ends thanks again.

    Just a quick question before I start from a new can the raspberry pi 4 4gb run a mavn project/jar application? Because this is my final goal to run this application on a raspberry pi
    3 years ago

    Stephan van Hulst wrote:Your problem is caused because you're trying to call new MediaPlayer(media) in the initialize() method of your videoSelectionController, but media hasn't been assigned a value yet.

    Don't create a MediaPlayer in the initialize() method. Create one inside the videoPlay() method.

    Also, please follow proper Java naming conventions. VideoSelectionController should be written with a capital letter.




    Hi,

    Finally I got that anoying nullpointer behind thanks for everyone here, but another issue is there. The video itself is not playing at all, is there any limit on what JavaFx can play?`There is no error messages or anything alike so I can not really debug..

    Here is the latest working code:

    VideoSelectionController





    I now can come without any problem to the screen with the mediaView but can not make it play, and there is no errors whatsoever
    3 years ago

    Paul Clapham wrote:

    jack turret wrote:



    First of all you have a relative path here. So it's possible that its answer to the question "What's this path relative to?" is different than your answer, and so the media isn't found. That would cause the NPE. Likewise there's some obscure code which produces a file name, which also raises the possibility of not finding the media and resulting in an NPE.

    All of this business of restructuring the design and code may or may not be relevant; it may just be that you have a bad path in your code.



    Well I am an amateur, do you have an idea how I could do it? This was kind of the best solution I had found
    3 years ago

    jack turret wrote:I debugged my code and noticed that videoplayer is null but I can not think of a reason why.



    So I edited my code today again and I think the real problem lies in passing the selectionMedia (the one where the path is saved from video file). I debugged and tried to pass in the data with a getter but still it did not work.


    Initialize of videoPlayerController:



    videoSelectionController:
    3 years ago
    Hi,

    So I have a javaFx application, in which I want the user to be able to see thumbnails of his videos on a specific folder. After researching a bit I found out that most videos have in their metadata information about thumbails. So theoretically I have to extract the metadata and display the thumbnail inside.

    But I could not really find out which library to use or could not use the ones I had found. This community here has helped me a lot with another problem (still is), so I hope you guys can give me a few pointers.
    3 years ago
    I debugged my code and noticed that videoplayer is null but I can not think of a reason why.
    3 years ago

    Stephan van Hulst wrote:That is because you're not using the resource path correctly. The resource path is not a file system path. It is a path inside a Java package of classes.

    Assuming that the src folder is the root of your package hierarchy, the path to use is "/view/videoPlayerView.fxml". Don't forget the forward slash at the start, otherwise Java will look for your resource relative to the package that your controller class is in.



    Hi,
    I had tried that at first but still getting that FxmlLoadError. But I had misinterpreted the error. The real problem is that my media is still null, even though on button click the path is extracted correctly... This is my edited code.


    Class to select the media








    I am really confused why this is not working I am going to go crazy sitting on it for two days    
    3 years ago

    Stephan van Hulst wrote:Ahh sorry. Rename getWindow(Event event) to getStage(Event event) and change its implementation to this:

    The rest of your code can remain the same.



    Hey sorry to annoy this much.. but now I am getting





    I tried to copy the path directly from my project folder I can navigate with control and mouse click directly to the fxml so it does find it, but still when running the program it does not work..
    3 years ago

    Stephan van Hulst wrote:Yeah, but the initialize() method is probably never called. That's because you are creating the controller class manually, instead of letting FXMLLoader do it.

    Don't create controllers by calling their constructors. Ditch viewSwitcherMethod() and instead create the new scene as I've shown you.



    I changed everything so far but this line



    is giving me the following error: 'setScene(javafx.scene.Scene)' has protected access in 'javafx.stage.Window'


    this is the changed method


    3 years ago

    Stephan van Hulst wrote:What does your view switcher do? I feel that your problem is caused because you are not using the regular way to instantiate FXML controllers. Also, you need to treat the initialize() method like you treat constructors: Use them for initialization of fields ONLY. Don't perform any business logic in constructors or initializers.

    You'll want to do something like this:

    EventUtilities




    Hi,

    ViewSwitcher is my class where I have all my methods to switch from view I wanted to have it all in one place. I changed the code so far as I have understood your advice.


    I edited my videoPlayerController like this:




    VideoSelection class is know looking like this:



    My error looks like this




    So with this code I noticed media is not null anymore but player (MediaPlayer) is null, even though I am intializing it in intiliaze method.
    3 years ago
    In my project I have to send one mediaObject with its path to another controller on buttonclick and then play it automatically, but when I send it my Media is null. What I tried so far is to use a setter before switching to the videoPlayer eventhough the setter is working the media is still null, and I tried to Instantiate an object of my previous controller and access it directly, but both failed.

    My Code to send the Media object: Here I select the path to a specific mediafile per image click. Here I am calling the setMedia method from the videoPlayer Controller then set it to selectionMedia which holds the path to my selectedMedia.



    My videoPlayer Controller with initialize override and the setter:In this controller I want the initialize method to just parse the mediaObject from the other controller to my player and start playing it automatically. I debugged it and the setter does indeed work and gets my mediaObject from the other controller but initiliaze does not seem to register it.

    3 years ago

    Campbell Ritchie wrote:JT: please read this.



    hey I am sorry you are right. Its just that I am sitting on this since yesterday with no improvement I was getting a little bit unpatianed
    4 years ago