Open Files

I'm using the code from this example to open a file.

https://www.processing.org/reference/selectInput_.html

The issue I am having is that the code in my Setup and Draw function is starting to execute before I select a file.

I need my sketch to wait until I choose a file then proceed.

Any ideas?

Thanks.

Phil

    void setup() {
      selectInput("Select a file to process:", "fileSelected");

      size(img.width, img.height);


    }

    void draw() {  



    }




    void fileSelected(File file) {
      if (file == null) {
        println("Window was closed or the user hit cancel.");
      } else {
        println("User selected " + file.getAbsolutePath());
        img = loadImage(file.getPath());  // Load the image into the program  


      }
    }

Answers

  • edited November 2014

    I tried your code and I get a NULL pointer exception on this line :

    image(myMovie, 0, 0, 600, 400);

    Below is my code..

    Any ideas?

    Thanks.

    Phil

    import javax.swing.*; 
    import processing.video.*;
    import com.heroicrobot.dropbit.registry.*;
    import com.heroicrobot.dropbit.devices.pixelpusher.Pixel;
    import com.heroicrobot.dropbit.devices.pixelpusher.Strip;
    import java.util.*;
    boolean fileSelected;
    String path;
    
    int stride = 78;
    
    Movie myMovie;
    DeviceRegistry registry;
    PusherObserver observer;
    
    void setup() {
      size(600,400);
      registry = new DeviceRegistry();
      observer = new PusherObserver();
      registry.addObserver(observer);
      registry.setAntiLog(true);
    
    selectMovie();
    
    
    
      if (fileSelected) {
        myMovie = new Movie(this, path);
        myMovie.loop();
      }
    }
    
    void draw() {
    
      if (fileSelected) {
      image(myMovie, 0, 0, 600, 400);
    scrape();
      }
    }
    
    void movieEvent(Movie m) {
      m.read();
    }
    
    
    
    
    void selectMovie()
    {
      selectInput("Select a movie to play:", "fileSelected");
    }
    
    
    
    
    
    void fileSelected(File selection) 
    {
      if (selection != null) 
      {
        path = selection.getAbsolutePath();
        fileSelected = true;
        println("User selected " + path);
      }
    }
    
  • I believe you still hadn't realized that selectInput() doesn't block. Program goes on w/o waiting for it to finish!
    You gotta keep checking whether it was successful all the time, unfortunately. /:)

  • void setup() { selectInput("Select a file to process:", "fileSelected");

    size(img.width, img.height);

    }

    void draw() {

    }

    void fileSelected(File file) { if (file == null) { println("Window was closed or the user hit cancel."); } else { println("User selected " + file.getAbsolutePath()); img = loadImage(file.getPath()); // Load the image into the program

    } }

    Can i get an alternate to select input, i have to specify the path in the location itself anf call back it.

  • please don't bump threads from 2014.

    if the above answers don't already solve your problem then start a new thread. and format your code nicely by selecting it and pressing ctrl-o

Sign In or Register to comment.