Help with Minim volume & other features

When i try to change the volume it says “Volume is not supported.” and i want to change the speed of the song! Is that possible?

You don’t give many details. Showing your code could be a begin :wink:

1 Like
import ddf.minim.*;
import java.io.*;

Minim minim;
AudioPlayer player;
String[] songs;
int currentSongIndex = 0;
float songVolume = 0.5;

void setup() {
  size(400, 200);
  
  // Define the directory where your songs are located
  String dir = "/home/nuhuhwy/Documents/Music/";
  songs = listFiles(dir);
  
  if (songs.length > 0) {
    minim = new Minim(this);
    loadSong(currentSongIndex);
  } else {
    println("No songs found in the directory.");
  }
}

void draw() {
  background(255);
  fill(0);
  textSize(16);
  text("Now Playing: " + songs[currentSongIndex], 20, 30);
  text("Volume: " + songVolume, 20, 60);
}

void keyPressed() {
  if (key == ' ') {
    if (player.isPlaying()) {
      player.pause();
    } else {
      player.play();
    }
  } else if (key == 's') {
    skipSong();
  } else if (key == 'l') {
    lastSong();
  }
}

void skipSong() {
  currentSongIndex = (currentSongIndex + 1) % songs.length;
  loadSong(currentSongIndex);
}

void lastSong() {
  currentSongIndex = (currentSongIndex - 1 + songs.length) % songs.length;
  loadSong(currentSongIndex);
}

void loadSong(int index) {
  if (player != null) {
    player.close();
  }
  
  player = minim.loadFile(songs[index]);
  player.setLoopPoints(0, player.length());
  player.setVolume(songVolume);
  player.play();
}

String[] listFiles(String dir) {
  File file = new File(dir);
  if (file.isDirectory()) {
    File[] fileList = file.listFiles(new FilenameFilter() {
      @Override
      public boolean accept(File dir, String name) {
        return name.endsWith(".mp3") || name.endsWith(".wav");
      }
    });
    if (fileList != null) {
      String[] filenames = new String[fileList.length];
      for (int i = 0; i < fileList.length; i++) {
        filenames[i] = fileList[i].getAbsolutePath();
      }
      return filenames;
    }
  }
  return new String[0];
}

void stop() {
  if (player != null) {
    player.close();
  }
  if (minim != null) {
    minim.stop();
  }
  super.stop();
}

this is my code right now, i would want to add a pitch, speed, a image of the album art if avaiable and volume controll. the volume gives an error.

Thanks :slight_smile:

2 Likes

So i found out an easy way to get the song icon!

String bashScriptPath = "/home/nuhuhwy/Music/script.sh"; // Update this with the actual path
PImage image;

void setup() {
    size(400, 200);
    background(255);
    String mp3FilePath = "/home/nuhuhwy/Music/Chipflake's Intro Expanded.mp3"; // Update this with the actual path

    // Run the Bash script and pass the MP3 file path as an argument
    executeBashScript(mp3FilePath);
    
    image = loadImage("/home/nuhuhwy/Music/file.jpg");
}

void executeBashScript(String mp3FilePath) {
    String[] command = {"bash", bashScriptPath, mp3FilePath};
}

void draw() {
    // Your Processing drawing code here
    image(image,0,0,100,100);
}

bash:

#!/bin/bash

mp3_file="$1"

if [[ -n "$mp3_file" ]]; then
    directory=$(dirname "$mp3_file")
    ffmpeg -i "$mp3_file" -an -c:v copy "$directory"/file.jpg
    echo "Conversion complete!"
else
    echo "No MP3 file selected."
fi

this works very well, altho i dont know if it does on windows.