Reinilton Posted April 26, 2015 at 08:41 PM Report Share #581889 Posted April 26, 2015 at 08:41 PM (edited) Fiz este código para reprodução de áudio, agora preciso pausar, sei que tenho que capturar onde parou o áudio quando clicar em Pause mas ainda não sei como fazer isso. import java.awt.Button; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JPanel; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import javafx.scene.media.AudioClip; public class Player extends JFrame implements ActionListener{ JPanel panel = new JPanel(); File file; FileInputStream fis; BufferedInputStream bis; Button btnPlay, btnStop, btnPause; AudioClip minhaMusica; public Player() { super("Janela"); setSize(400,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setLayout(null); btnPlay = new Button("Play"); btnPlay.setBounds(10, 10, 80, 30); add(btnPlay); btnStop = new Button("Stop"); btnStop.setBounds(10, 50, 80, 30); btnStop.setEnabled(false); add(btnStop); btnPause = new Button("Pause"); btnPause.setBounds(10, 90, 80, 30); btnPause.setEnabled(false); add(btnPause); btnPlay.addActionListener(this); btnStop.addActionListener(this); btnPause.addActionListener(this); minhaMusica = new AudioClip(Player.class.getResource("who_knew.mp3").toString()); } public static void main(String[] args) { new Player().setVisible(true); } @Override public void actionPerformed(ActionEvent e) { if(e.getSource()==btnPlay){ if (null != minhaMusica) { minhaMusica.play(); } btnPlay.setEnabled(false); btnStop.setEnabled(true); btnPause.setEnabled(true); } if(e.getSource()==btnStop){ if (null != minhaMusica) { minhaMusica.stop(); } btnPlay.setEnabled(true); btnStop.setEnabled(false); btnPause.setEnabled(false); } if(e.getSource()==btnPause){ btnPlay.setEnabled(true); btnStop.setEnabled(false); btnPause.setEnabled(false); } } } Edited April 26, 2015 at 09:18 PM by apocsantos geshi Link to comment Share on other sites More sharing options...
siul72 Posted May 15, 2015 at 06:23 PM Report Share #583243 Posted May 15, 2015 at 06:23 PM Procura na documentacao da classe: javafx.scene.media.AudioClip .... bem, eu fui ler a documentacao e.... An AudioClip represents a segment of audio that can be played with minimal latency. Clips are loaded similarly to Media objects but have different behavior, for example, a Media cannot play itself. AudioClips are also usable immediately. Playback behavior is fire and forget: once one of the play methods is called the only operable control is stop(). An AudioClip may also be played multiple times simultaneously. To accomplish the same task using Media one would have to create a new MediaPlayer object for each sound played in parallel. Media objects are however better suited for long-playing sounds. This is primarily because AudioClip stores in memory the raw, uncompressed audio data for the entire sound, which can be quite large for long audio clips. A MediaPlayer will only have enough decompressed audio data pre-rolled in memory to play for a short amount of time so it is much more memory efficient for long clips, especially if they are compressed. Logo esta classe nao é a melhor opccao quando precisas de fazer pause.... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now