I was following closely the example given on "Programming Interactivity" by Joshua Nobel.
Ok. Basically what the example does is that it should play an mp3 file. I have already put "song.mp3" under the "data" folder. But when I tried to play the sketch, I am getting,
"cannot convert from AudioPlayer to AudioPlayer"
I can't seem to be able to see anyone who is having the same problem as me.
The below codes were executed on Processing IDE.
import ddf.minim.*;
AudioPlayer song;
Minim minim;
void setup() {
size(800, 800);
minim = new Minim(this);
song = minim.loadFile("song.mp3");
song.play();
}
Can someone please tell me why am I having this error?
I did this instead and it works!!!
import ddf.minim.*;
ddf.minim.AudioPlayer song;
Related
I have some problems to understand how to play some tracks
one after the other avoiding the overlap effect.
I am using the Minim library but I did not find a way
to detect the final moment of the first sound to start the second one.
Can anybody give me my some tips?
this is my sketch
import ddf.minim.*;
Minim minim;
AudioPlayer player[]=new AudioPlayer[4];
String filenames[] = new String[]{"sound1.mp3", "sound2.mp3"};
void setup(){
minim = new Minim(this);
for(int i=0;i<2;i++){
player[i] = minim.loadFile(filenames[i]);
player[i].play();
print(filenames);
}
}
void draw(){}
void stop(){
for(int i=0;i<2;i++){
player[i].close();
}
minim.stop();
super.stop();
}
You can poll player[i].isPlaying() to see if the sound is still playing before starting the next one. In your code, this means keeping track of which player is currently active, and moving the call to the .play() method into draw().
Could someone please help and tell me what the code would be to insert sound into my xcode 6 swift project and have it playing in the background
For OS X, to get sounds to play you can either use NSSound or for more advanced things Core Audio.
With NSSound (the easiest way) you would put a sound file in your assets library, and then do:
var sound = NSSound(named: "name_of_sound")
sound.play()
For iOS try the following code:
import UIKit
import AVFoundation
class ViewController: UIViewController {
var audioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("sound_name", ofType: "wav"))
println(alertSound)
// Removed deprecated use of AVAudioSessionDelegate protocol
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
var error:NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)
audioPlayer.prepareToPlay()
audioPlayer.play()
}
}
and it seems to be a good idea in general to have the audio player as a class member
Ok, here's the code:
import java.io.*;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import sun.audio.*;
public class Sound {
public static void main ( String Args[]){
JFileChooser openf =new JFileChooser();
openf.showOpenDialog(null);
File fl= openf.getSelectedFile();
String sound = fl.getAbsolutePath();
JOptionPane.showMessageDialog(null, sound);
InputStream in;
try{
in = new FileInputStream(sound);
AudioStream audio = new AudioStream(in);
AudioPlayer.player.start(audio);
}catch(Exception e){
JOptionPane.showMessageDialog(null, e.toString());
}
}
}
Im working this application to allow the selection of audio files (through the jfilechooser) such as: mp3, wma or wav for its reproduction.
The exception I keep having is the following: 'java.io.IOException: could not create audio stream from input stream'.
I heard somewhere else that some of the sun.audio classes im importing were having some problems. Could that be?
Thanks.
Miguel André.
I guess you are trying to play an mp3 file. Java doesnt support mp3 natively. Your code is capable of playing wave(*.wav) files only. JavaFX supports mp3 out-of-the-box. Java supports MP3 with use of an external plug-in(JMF,FMJ,JLayer ..)
I was wondering if there was a processing code that will let me use sound only when i press the mouse and stops when I release it. I already have the audio that I want to use loaded onto processing but I'm having difficulty finding the code. Please help me! Thank you!
Your question is very vague, but I'll do my best to answer.
I don't think there's any way to handle audio with Processing's built-in functions, but the minim library works well with it. I'm going to assume that's what you're using for this solution.
As I understand it, you'd like to press the mouse, start the sound, and when the mouse is released you'd like to stop the sound, rather than pause it. We can accomplish this using processing's built-in mousePressed and mouseReleased methods like so:
import ddf.minim.*;
Minim minim;
AudioPlayer player;
AudioInput input;
void setup()
{
//let's make the window a little bigger
size(400,400);
minim = new Minim(this);
player = minim.loadFile("song.mp3");
input = minim.getLineIn();
}
void draw(){ }
void mousePressed()
{
player.play();
}
void mouseReleased()
{
player.close();
//since close closes the file, we'll load it again
player = minim.loadFile("song.mp3");
}
The code for pausing would look very similar, except you would replace everything in the mouseReleased block with the following:
player.pause();
I wanna create some loading dots like this:
At 0 second the text on the screen is: Loading.
At 1 second the text on the screen is: Loading..
At 2 second the text on the screen is: Loading...
At 3 second the text on the screen is: Loading.
At 4 second the text on the screen is: Loading..
At 5 second the text on the screen is: Loading...
and so forth until I close the Stage.
What is the best / easiest way to make that in JavaFX? I've been looking into animations/preloaders in JavaFX but that seems to complex when trying to achieve this.
I've been trying to create a loop between these three Text:
Text dot = new Text("Loading.");
Text dotdot = new Text("Loading..");
Text dotdotdot = new Text("Loading...");
but the screen stays static...
How can I make this work correctly in JavaFX? Thanks.
This question is similar to: javafx animation looping.
Here is a solution using the JavaFX animation framework - it seems pretty straight forward to me and not too complex.
import javafx.animation.*;
import javafx.application.Application;
import javafx.event.*;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Duration;
/** Simple Loading Text Animation. */
public class DotLoader extends Application {
#Override public void start(final Stage stage) throws Exception {
final Label status = new Label("Loading");
final Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO, new EventHandler() {
#Override public void handle(Event event) {
String statusText = status.getText();
status.setText(
("Loading . . .".equals(statusText))
? "Loading ."
: statusText + " ."
);
}
}),
new KeyFrame(Duration.millis(1000))
);
timeline.setCycleCount(Timeline.INDEFINITE);
VBox layout = new VBox();
layout.getChildren().addAll(status);
layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
stage.setScene(new Scene(layout, 50, 35));
stage.show();
timeline.play();
}
public static void main(String[] args) throws Exception { launch(args); }
}
Have you considered to use a Progress Indicator or a Progress Bar? I think they can be a good solution to show an animation and avoid problems.
I've been able to do it in JavaFX, not with Animations, but using the concurrency classes from JavaFX.
I let you the code here in a gist. I think it isn't very intuitive, because I prefer a progress indicator. And maybe it isn't the best solution, but maybe this will help you.
Cheers