createFileInput function

I create the code like this
but the error keeps popping up.
what’s should I do?

let song;
let input;

function setup() {
input = createFileInput(handleFile);
input.position(0, 0);
createCanvas(720, 200);
background(255,0,0);
}

function handleFile(file) {
print(file);
if (file.type === ‘mp3’) {
song = songPlay(“audio”);
song.hide();
} else {
song = null;
}
}
function mousePressed() {
if (!song.isPlaying())
{song.stop();
background(255,0,0);
}
else {
song.play();
background(0,255,0);
}
}

Hello,

welcome to the forum!

Great to have you here!

Sorry, I don’t know.

In processing AND using minim library like shown below.

Warm regards,

Chrisir


import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

File result = null;
File resultOld; 

Minim       minim;
AudioPlayer song;

boolean Loaded=false; 
boolean pause = false; 

void setup() {
  size(720, 200);
  background(0);

  minim = new Minim(this);
  selectInput("Select a song to load:", "fileSelected");
}

void draw() {

  // better use int state here: it can be : waitForLoad, loadSong, playSong, songPaused

  if (result==null) {
    //wait
    background(0);
    fill(255); 
    String s1= "Hit any key to load a new song ++ " ; 
    text(s1+s1+s1+s1+s1+s1+s1+s1, 1, 55);
  } else {
    // We got a result from the Load Dialog: 
    if ( ! Loaded) {
      // Load a soundfile and play it back
      Loaded = true; 
      song =  minim.loadFile( result.getAbsolutePath(), 1024); //  new SoundFile(this, result.getPath());
      song.play();
      background(0, 255, 0);  // green - green means we play a song
    } else {
      // playing song
      // show screen Pause / Play 
      if ( pause ) {
        // Pause
        background(255, 0, 0);   // red = Pause
        fill(0); 
        text("Pause. Press nouse to play", 55, 55);
      } else {
        // Play 
        background(0, 255, 0);  // green - green means we play a song
        fill(0); 
        text(result.getAbsolutePath()
          +"\nPress mouse to pause."
          +"\nHit any key to load a new song", 55, 55);
      }//else
    }//else
  }//else
}//func 

void fileSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
    // Did we have a song already?
    if (song!=null) { 
      // restore old song
      song.play(); 
      result=resultOld; 
      Loaded=true; 
      background(0, 255, 0);  // green - green means we play a song 
      pause=false;
    }//if
  } else {
    println("User selected " + selection.getAbsolutePath());
    result = selection;
  }//else
}//func 

void mousePressed() {
  if (song==null) 
    return; 

  // toggle 
  if ( pause ) {
    song.play();
    pause=false;
  } else {
    song.pause();
    pause=true;
  }
}

void keyPressed() {
  // load a new song
  background(0);
  Loaded=false; 
  pause = false;
  resultOld=result; 
  result = null;
  if (song!=null) 
    song.pause();
  selectInput("Select a song to load:", "fileSelected");
}
//
1 Like