Play Pause Sound In Java?

Jan 15, 2015

What I want to do is very clear, just play sound and pause it. The problem is that I can't pause the music. When I click the pause button music keeps playing .I have been working on for 2 hours. I can't find the mistake; what am I doing wrong?

public class MainC extends JFrame implements Runnable,ActionListener {
private JPanel contentPane;
private JTextField txtname;
JButton btnopen;
JButton btnSave;
JButton btnplay;

[code]....

View Replies


ADVERTISEMENT

Play / Stop / Pause Song Java Applet

Jul 22, 2014

In my card game applet I have to play some music and the user must have the ability to play, stop and pause the song using buttons. I got the play and stop to work easy but I'm unable to add the pause option/method.

View Replies View Related

Play A Sound When Button Is Clicked?

Mar 20, 2014

im trying to play a sound when button is clicked. here is the following code

InputStream in;
try {
in = new FileInputStream(new File("failure1.wav"));
AudioStream audios = new AudioStream(in);
AudioPlayer.player.start(audios);
} catch (Exception e) {
}

just wondering why it does load;

i do get the warning

warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioPlayer is internal proprietary API and may be removed in a future release
AudioPlayer.player.start(audios);

View Replies View Related

Sound Clip Using Mediatools Class Will Not Play

Oct 5, 2014

I wrote the below program to set up and play the game breakout as an assignment for Stanford's CS106 programming class. I wrote it on my old mac running OSX 10.6.8, with the version of Eclipse JDK that works on that machine. When I tested it back on the mac, the program worked normally. But now I am using a Windows 8.1 computer with the corresponding version of eclipse, and when I test the program again, the sound effect I coded does not play. I get the following error message in console when the ball hits the paddle or brick, which previously caused the sound clip to play.

Exception in thread "Thread-4" java.lang.IllegalArgumentException: Requested value -120.0 smaller than allowable minimum value -80.0.
at javax.sound.sampled.FloatControl.setValue(Unknown Source)
at com.sun.media.sound.DirectAudioDevice$DirectDL$Gain.setValue(Unknown Source)
at acm.util.SoundPlayer.setLineVolume(SoundClip.java:909)
at acm.util.SoundPlayer.run(SoundClip.java:860)
at java.lang.Thread.run(Unknown Source)

why my code would request a value below the min. I am using the mediatools class that is part of the ACM libraries we are required to use for the class to play the sound in question, found here: URL....I went ahead and tested all parts of the program and the missing sound effect is the only problem. Here is my complete code:

package Breakout_package;

import acm.graphics.*;
import acm.program.*;
import acm.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

[code]....

View Replies View Related

Sound Won't Play When Player Dies And A Game Over Screen Pops Up

Jan 14, 2014

I am making a game with java in a program called greenfoot.My problem is that a sound won't play when the player dies and a Game Over screen pops up..

- I have saved the audio file in my sound map of the scenario
- Applied the good name of the file
- tested the sound effect and it's working

this is my code:

public GameOver()
{
setImage(new GreenfootImage("GAME OVER", 100, Color.BLACK, null));
Greenfoot.playSound("fail-trombone-03.wav");
Greenfoot.stop();
}

View Replies View Related

Applets :: Accessing External Resources - Play Particular Sound Whenever Button Is Pressed

May 4, 2014

I am quite new to developing Applets in java. I recently made an applet that will play a particular sound whenever a button is pressed. The sound files are placed in the same directory as the applet class file and i access them by using

AudioClip clip=getAudioClip(getCodeBase(),"A.wav").

The Applet runs fine in the appletviewer but whenever I try to open it using any browser like Chrome,IE,Firefox the applet loads but sound isn't played. I checked the java console and it showed

"java.security.AccessControlException: access denied ".

My questions are:

1. How do I allow the applet to get access to those files?

2. When the Applet is running from the local file system why CAN NOT I access those resources via getCodeBase() ???

3. I googled and found that I can sign a JAR and that can have full access to the computer. But how do I create a JAR from an applet (which has no Main method) while it asks me to point to the main class in the manifest?

View Replies View Related

Speed Of Sound Java

Jul 27, 2014

I can't get the output to read correctly. I get 0 as the answer.

import java.util.Scanner;
public class TheSpeedofSound777
{

public static void main(String[] args)
{

System.out.println("Gordon Elam Sr July 26, 2014 ");

[code]...

View Replies View Related

Receive Data From Midi Device With Java Sound API

Mar 15, 2014

I haven't been able to find a cut and paste working example of how to receive MIDI data from a MIDI device, like my piano, and display something to System.out.There are all sorts of examples for synthesizers, sequencers and sending data to a MIDI device, but I have not been able to find a single example of how to receive MIDI data and just display a simple message.

I just need something simple that works to start playing with it, and understanding how it works. Having a working example would also support understanding the Sound API descriptions. They read like differential equations texts books to me, i.e. not clear at all.

I have a working example of how to poll all devices and getDevice.info, which is supposed to then be used to address a specific MIDI device.

I've also looked at a number of books, in the store and on line.I haven't seen a single example anywhere.the closest I found to working examples was on StackOverflow, but I didn't understand some of the other code in the examples, which may or may not have been working correctly anyway.

View Replies View Related

How To Play WMA Or MP3 Files In Java

Jan 23, 2014

I was looking at the Sound API pages in the java tutorials. I was planning to use it to run wma files. Fortunately, for me, I found, soon into the tutorials, that these API DON'T support the type I have all of my files in (I have a ton of wma files but none of the libraries mentioned support them.)

I almost thought I heard JavaFx or whatever it's called does, but that sounds foreign and Netbeans lists it as a separate type of java in a way, so I don't know if it would be cross-platform or if it could work with the JavaSE API.) Nor do I know what JavaSX or whatever it's called is really, other than that it's more for internet than application.

If I wanted a JPanel or Applet acting as the content pane of a JFrame or being in a JFrame, could I use JavaFX (or whatever it's called) or some third party library (that I always tend to end up spending hours on trying to get it to find the jar files when I import them, so I hope I don't need too many jar files!!!! ) would it work with the JavaSE API?

I don't know much about Java and playing sounds (other than that there is a static method, I think under Toolkit, that will play a system beep) with programs.

However, I can see that that packages don't support certain types (so much for cross-platform!!!!!!! ) and also that a while back that Oracle took over and that they aren't really updating the Java Sound APIs really that much at all

So, without having to learn a whole new Java set of standards (assuming JavaFX or whatever it's called is a different set of standards from JavaSE), is there a way to play .wma?

That's all I seem to have on my computer.

(I suppose I could create new sounds, though if Oracle isn't updating the library, who knows if even that works anymore, but if you're trying to run a Java Media Player that runs lots of DIFFERENT sound file types, this seems a real setback. )

I heard you could convert them to MP3s (I heard there were free things that did it, but who knows if the things aren't filled with viruses that'll do it or, even if they're not, that they'll really mess up the quality of the sound and that I might lose the old .wma file in the process even if it doesn't corrupt the sound.)

But, even if I get a .mp3, I heard the main JavaSE libraries DON'T cover that either, though it was said it was easier to make it run them than .wma files.

MediaPlayer and the main JavaSE classes don't seem to be able to fit for this type of program (a java media player) that I was planning. Heck, they can't even play any music I have on my computer at all, media player or not.

View Replies View Related

How To Play MP3 Files From Java Program

Dec 26, 2014

I wanted to build an mp3 player as a Java project. One crucial part of the project involves being able to play an mp3 fie. I am not able to find the right api (if one exists) and am not able to find a suitable answer when searching on the web. A simple code snippet illustrating the playing of mp3 file using Java program. Also, I am using Eclipse IDE and how to import files if any importing of files is required.

View Replies View Related

How To Play Video Into Java Application

Feb 10, 2015

How to insert and play a video or a music background in a java application. Let me explain better... I need to develop a game where sometime I need to show picture, or play videos and also, if is possible, add a music in background... I work with eclipse and I know quite good the main concept of java's language...

View Replies View Related

How To Play YouTube Video In Java Application

May 29, 2014

I am writing a java application that can play youtube video by given URL. first i tried with JPaneleditor, then now i am trying google youtube api, but maybe api is abit too tough for me.

I am using netbeans....

View Replies View Related

Make A Pause Between Every Loop

Feb 18, 2015

I've been learning Java in school for lika a year now. Our teacher wanted us to make a game called "Game of Life" .Now it's not very optimized because the only type of GUI we know how to make it with JButtons so if I want a 100x100 grid that means the program has to load 10000 buttons and change text and color on them which I can imagen cause lags and so on but if we ignore that lagg our teacher wanted us to make it loop-able and well I kinda succeeded but the only problem is that I can't get it to wait between every loop so if I tell the program to loop 100 times, the program processes that and that takes forever and then updates the board and sometimes it takes forever and sometimes you cant even see the "cells" moving. Is it possible to get my program to loop and if so how? Here is the code:

//------------------------------------------------------------------------------------------------------------------------
// Hamta standardpaket
//------------------------------------------------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

[code]....

View Replies View Related

Applets :: Pause / Resume Audio?

Jul 22, 2014

I'm trying to learn how to Pause/Resume audio in an applet .

View Replies View Related

Pause And Resume Thread Using MouseClick?

Oct 30, 2014

Here I want to make a simple program where a Ball keep bouncing forever, then I add a MouseClick Listener to stop and resume thread (I mean, to stop moving Ball and to resume again). The problem is I can stop the thread using wait(), But I can not resume it. Below is the code

public class TestResumePauseBall {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public synchronized void run() {
Field aField = new Field();

[code]....

At first I think that notify() must be called from another active thread. So I add a 'class Timing implements Runnable'. Then I call notifyAll() from class Timing. But still it was failed.

After wait() called on Ball's thread, the whole frame also freeze. I can not understand why this happen?

If this test success, I will add 1 one more ball and add keyboard keys as controller of ball's movement.

View Replies View Related

Pause / Unpause With Single Key Input

May 27, 2014

I am coding a game and I am trying to implement a pause and unpause button. in the BoardPanel class I've added the button's 'p' and 'o' to game.wait() and game.notify() (main code is in game class). however the game.wait is having issues and even if i throw interrupted exception or try/catch it doesn't work. I'd like to code it to a single button if at all possible.

View Replies View Related

How To Loop A Sound

Sep 24, 2014

I created a game but want some music in it, and as I write in the title i want the sound to loop. This is the code fore the sound class i have:

Java Code:

import java.applet.Applet;
import java.applet.AudioClip;
public class Sound {
private AudioClip clip;
//all sounds
public static final Sound ScoreSound = new Sound("/Score.wav");
public static final Sound BounceSound = new Sound("/Bounce.wav");

[code].....

View Replies View Related

How To Get Sound To Import It To Game

Apr 7, 2015

how to make a simple game. I am having trouble when it comes to adding sound though. It tells me to do this:

package net.game.Game;
 
import java.applet.Applet;
import java.applet.AudioClip;
 public class Sound {
public static final AudioClip BALL = Applet.newAudioClip(Sound.class.getResource("ball.wav"));
public static final AudioClip GAMEOVER = Applet.newAudioClip(Sound.class.getResource("gameover.wav"));
public static final AudioClip BACK = Applet.newAudioClip(Sound.class.getResource("back.wav"));
}

What this does is it gets the sound file then gives it a name(BALL=ball.wav GAMEOVER=gameover.wav ect..) and then there is other code in other classes that call the sound so it will run but it keeps giving me an error and I don't know what to do. How can I get it to import the sound? Here is the error.

PHP Code:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at net.game.Game.stuff.<init>(stuff.java:35)
    at net.game.Game.stuff.main(stuff.java:62)
Caused by: java.lang.NullPointerException
    at sun.applet.AppletAudioClip.<init>(Unknown Source)
    at java.applet.Applet.newAudioClip(Unknown Source)
    at net.game.Game.Sound.<clinit>(Sound.java:7)
    ... 2 more 

View Replies View Related

Speed Of Sound Program

Feb 11, 2015

I have to write a program that asks the user to enter "air", "water", or "steel", and the distance that a sound wave will travel in the medium. The program should then display the amount of time it will take. The amount of time it takes sound to travel in air can be calculated as follows;

Time = Distance/1,100

The amount of time it takes sound to travel in water can be calculated with the following formula:

Time=Distance/4,900

The amount of time it takes sound to travel in steel can be calculated with the following formula:

Time=Distance/16400

Here is my code:

import java.lang.String;
/**
This program displays numbers padded with leading zeros.
*/
 
public class SpeedofSound {
public static void main(String[] args) {
double D; // declares this as double
D = keyboard.nextDouble();
 const double A = 1100; // declares this as a constant

[Code] .....

The following is the error I'm getting:

----jGRASP exec: javac SpeedofSound.Java
error: Class names, 'SpeedofSound.Java', are only accepted if annotation processing is explicitly requested
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

View Replies View Related

How To Synthesize Simple Sound

Sep 15, 2014

Okay, so I'm looking for a way to synthesize sound, and from what I've found around the interwebs it seems amazingly complex. Is there really not a function like "sound(wavelength, time)"? Alternatively a way to use an integer array to determine the acoutstic pressure at a given time, or some other way to determine the pressure at a given time?

View Replies View Related

Using Integer Array To Call Sound Samples

Nov 28, 2014

trying to get into Java and jump into just programming an idea.I want to go through an array of numbers at a certain pace and call different sounds as it goes through.

View Replies View Related

Using Primitive Data Types To Overload Sound Method

Jun 29, 2014

Trying to find a way to use primitive data types to overload sound()method. I can't seem to warp my head around using an int or a double to overload the method. And if I did, how do you call them in the main afterwards?

View Replies View Related

How To Add Play Again Choice To Hi Lo Game

Jun 17, 2014

I am a begMy task is to write a program that plays the "Hi Lo guessing game." The program runs smoothly. However, it does not proceed to the next game after the previous game is done. I need to add a "play again" choice to the program so that the user will continue to play until they have chosen to quit. I have tried several different ways but each one has failed. I am completely stuck on this. I have attached my code to this.

View Replies View Related

Can't Play Game Server

Jun 18, 2014

So, after my graphics card melted down, I decided to use a chat program because I can't play the game server which I am staff on. I've downloaded this:

CactusChat: MC 1.7.4 - 1.7.5 chat client for Windows, Mac and Linux Operating Systems | EcoCityCraft Economy | Minecraft Servers

After I knew it was a .jar file, it would basically fail, I would launch it, it turns into a cmd for 0.5 seconds, and closes without any progress. Typical, and expected.I downloaded the latest java update, removed 3 older versions, and now my Java SE Binary program went missing. I can't even launch it, and it tells me to look for another program to launch it with.

View Replies View Related

Play / Stop And Loop Three Different Songs

May 13, 2014

I am making a project that should play, stop, and loop three different songs (not at the same time). I am calling this SoundPlayer class from my main class:

import javax.sound.sampled.*;
import java.util.*;
public class SoundPlayer {
List<AudioInputStream> songs = new ArrayList<AudioInputStream>();
int currentSong, currentPlayType;

[Code] ....

When my class calls setPlayType(2), which should make it play, I get the following runtime error:

java.lang.NullPointerException
at SoundPlayer.playSong(SoundPlayer.java:32)
at SoundPlayer.setPlayType(SoundPlayer.java:64)
at MainPanel$AListener.actionPerformed(MainPanel.java:60)
(...)

Line 32 is if(clip.isOpen()), but I'm pretty sure I instantiated clip properly in the constructor.

View Replies View Related

IOException - How To Play Audio File

Apr 17, 2015

I used the following but there's an IOexception. How can I set it up so that it can play audio even after the jar is built?

public void play(){
InputStream in = null;
try {
in = new FileInputStream(new File(filename));
AudioStream audioStream = new AudioStream(in);
AudioPlayer.player.start(audioStream);
in.close();

[Code]...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved