當前位置: 首頁>>代碼示例>>Java>>正文


Java LineListener類代碼示例

本文整理匯總了Java中javax.sound.sampled.LineListener的典型用法代碼示例。如果您正苦於以下問題:Java LineListener類的具體用法?Java LineListener怎麽用?Java LineListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LineListener類屬於javax.sound.sampled包,在下文中一共展示了LineListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: play

import javax.sound.sampled.LineListener; //導入依賴的package包/類
/**
 * playback start method extended by some gui stuff
 */
@Override
public void play() {
    try {
        super.play();
    } catch (LineUnavailableException | IOException e) {
        e.printStackTrace();
    }
    panel[2].setText("\u25A0");
    panel[2].setBackground(new Color(232, 232, 232));

    // listen to the audioClip and when it is finished playing, trigger the stop() method to clean up and reset the button
    LineListener listener = new LineListener() {
        public void update(LineEvent event) {
            if (event.getType() == LineEvent.Type.STOP) {
                stop();
            }
        }
    };
    this.getAudioClip().addLineListener(listener);
}
 
開發者ID:cemfi,項目名稱:meico,代碼行數:24,代碼來源:MeicoApp.java

示例2: start

import javax.sound.sampled.LineListener; //導入依賴的package包/類
/**
 * Plays the clip with the specified volume.
 * @param volume the volume the play at
 * @param listener the line listener
 * @throws LineUnavailableException if a clip object is not available or
 *         if the line cannot be opened due to resource restrictions
 */
public void start(float volume, LineListener listener) throws LineUnavailableException {
	Clip clip = getClip();
	if (clip == null)
		return;

	// PulseAudio does not support Master Gain
	if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
		// set volume
		FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
		float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0);
		gainControl.setValue(dB);
	}

	if (listener != null)
		clip.addLineListener(listener);
	clip.setFramePosition(0);
	clip.start();
}
 
開發者ID:yugecin,項目名稱:opsu-dance,代碼行數:26,代碼來源:MultiClip.java

示例3: playSound

import javax.sound.sampled.LineListener; //導入依賴的package包/類
/**
 * <strong><em>playSound</em></strong><br /><br />
 * 
 * &emsp;Plays a .wav audio file located in /res/audio/.<br />
 * &emsp;<em>E.g.</em> <sub>audio</sub><br /><br />
 * &emsp;File location would be: <sub>/res/audio/audio.wav</sub><br />
 * &emsp;and would be played automatically.
 * 
 * @param audio - File name.
 */
public void playSound(String audio){
	try{
	    AudioInputStream audioInputStream =
	        AudioSystem.getAudioInputStream(
	        	 getClass().getResource("/audio/"+audio+".wav"));
	    Clip clip = AudioSystem.getClip();
	    clip.open(audioInputStream);
	    clip.start();
	    clip.addLineListener(new LineListener() {
			
			@Override
			public void update(LineEvent arg0) {
				if(arg0.getFramePosition()==clip.getFrameLength()){
					clip.close();
				}
			}
		});
	    clips.put(audio, clip);
	}catch(Exception e){
		e.printStackTrace();
	}
}
 
開發者ID:JediBurrell,項目名稱:neo,代碼行數:33,代碼來源:Audio.java

示例4: openClip

import javax.sound.sampled.LineListener; //導入依賴的package包/類
private Clip openClip(boolean closeAfterPlaying) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
	AudioInputStream audioStream = AudioSystem.getAudioInputStream(new ByteArrayInputStream(audioFilePath));
	DataLine.Info info = getLineInfo(audioStream);
	Clip audioClip = (Clip) AudioSystem.getLine(info);

	if (closeAfterPlaying) {
		audioClip.addLineListener(new LineListener() {
			@Override
			public void update(LineEvent myLineEvent) {
				if (myLineEvent.getType() == LineEvent.Type.STOP)
					audioClip.close();
			}
		});
	}

	audioClip.open(audioStream);
	return audioClip;
}
 
開發者ID:WorldGrower,項目名稱:WorldGrower,代碼行數:19,代碼來源:Sound.java

示例5: playSound

import javax.sound.sampled.LineListener; //導入依賴的package包/類
private static void playSound(File soundFile, Optional<LineListener> listener) {
	if (isSilenced) {
		System.out.println(soundFile.getPath());
		return;
	}

	if (!soundFile.isAbsolute()) {
		soundFile = new File(System.getProperty("shootoff.home") + File.separator + soundFile.getPath());
	}

	try {
		final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundFile);
		playSound(audioInputStream, listener);
	} catch (UnsupportedAudioFileException | IOException e) {
		logger.error(String.format("Error reading sound file to play: soundFile = %s", soundFile), e);
	}
}
 
開發者ID:phrack,項目名稱:ShootOFF,代碼行數:18,代碼來源:TrainingExerciseBase.java

示例6: setPlayer

import javax.sound.sampled.LineListener; //導入依賴的package包/類
public void setPlayer(Wavefile af) throws Exception{
	clip = af.getClip();
       clip.open();
       fullLength = clip.getFrameLength();
       endPoint = fullLength;
       gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
       playing = false;
       clip.addLineListener(new LineListener(){
		@Override
		public void update(LineEvent arg0) {
			while(playing){
				int tempframe = clip.getFramePosition();
				MakamBoxAnalysis.positionSlide.setValue(tempframe);
				if (stopbutton!=null&&tempframe == fullLength){
					stopbutton.doClick();
				} else if(stopbutton!=null && tempframe>=endPoint){
					playAgain();
				} else if (tempframe == fullLength){
					stop();
				}
			}
		}
       });
}
 
開發者ID:miracatici,項目名稱:MakamBox,代碼行數:25,代碼來源:Player.java

示例7: playSirenSound

import javax.sound.sampled.LineListener; //導入依賴的package包/類
private void playSirenSound() {
	try {
		File soundFile = new File(sirenFile);
		AudioInputStream soundIn = AudioSystem.getAudioInputStream(soundFile);
		AudioFormat format = soundIn.getFormat();
		DataLine.Info info = new DataLine.Info(Clip.class, format);
		clip = (Clip) AudioSystem.getLine(info);
		clip.addLineListener(new LineListener() {
			@Override
			public void update(LineEvent event) {
				if (event.getType() == LineEvent.Type.STOP) {
					soundOn = false;
				}
			}
		});
		clip.open(soundIn);
		clip.start();
		soundOn = true;
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:ELTE-Soft,項目名稱:txtUML,代碼行數:23,代碼來源:UI.java

示例8: start

import javax.sound.sampled.LineListener; //導入依賴的package包/類
/**
 * Plays the clip with the specified volume.
 * @param volume the volume the play at
 * @param listener the line listener
 * @throws LineUnavailableException if a clip object is not available or
 *         if the line cannot be opened due to resource restrictions
 */
public void start(float volume, LineListener listener) throws LineUnavailableException {
	Clip clip = getClip();
	if (clip == null)
		return;

	// PulseAudio does not support Master Gain
	if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
		// set volume
		FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
		float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0);
		gainControl.setValue(Utils.clamp(dB, gainControl.getMinimum(), gainControl.getMaximum()));
	} else if (clip.isControlSupported(FloatControl.Type.VOLUME)) {
		// The docs don't mention what unit "volume" is supposed to be,
		// but for PulseAudio it seems to be amplitude
		FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.VOLUME);
		float amplitude = (float) Math.sqrt(volume) * volumeControl.getMaximum();
		volumeControl.setValue(Utils.clamp(amplitude, volumeControl.getMinimum(), volumeControl.getMaximum()));
	}

	if (listener != null)
		clip.addLineListener(listener);
	clip.setFramePosition(0);
	clip.start();
}
 
開發者ID:itdelatrisu,項目名稱:opsu,代碼行數:32,代碼來源:MultiClip.java

示例9: playAudio

import javax.sound.sampled.LineListener; //導入依賴的package包/類
private void playAudio(AudioInputStream audio)
	{
		LineListener lineListener = new LineListener() 
		{
            public void update(LineEvent event) 
            {
                if (event.getType() == LineEvent.Type.START) { Log.print(Log.DEBUG,"Audio started playing."); }
                else if (event.getType() == LineEvent.Type.STOP) { Log.print(Log.DEBUG,"Audio stopped playing."); } 
                else if (event.getType() == LineEvent.Type.OPEN) { Log.print(Log.DEBUG,"Audio line opened."); } 
                else if (event.getType() == LineEvent.Type.CLOSE) { Log.print(Log.DEBUG,"Audio line closed."); }
            }
        };

        AudioPlayer ap = new AudioPlayer(audio, lineListener);
        ap.start();
}
 
開發者ID:scbickle,項目名稱:maryspeak,代碼行數:17,代碼來源:Process.java

示例10: VentanaInternaGrabador

import javax.sound.sampled.LineListener; //導入依賴的package包/類
public VentanaInternaGrabador(final File f) {
    initComponents();

    recorder = new SMSoundPlayerRecorder(f);
    this.setTitle(f.getName());
    LineListener lineListener = new LineListener() {
        @Override
        public void update(LineEvent event) {
            if (event.getType() == Type.START) {
                recorderButton.setEnabled(false);
                stopButton.setEnabled(true);
            }
            if (event.getType() == Type.STOP) {
                recorderButton.setEnabled(true);
                stopButton.setEnabled(false);
                VentanaInternaReproductor vir = new VentanaInternaReproductor(f);
                VentanaPrincipal.getEscritorio().add(vir);
                vir.setVisible(true);
            }

        }
    };
    ((SMSoundPlayerRecorder) recorder).setLineListener(lineListener);
    this.pack();
}
 
開發者ID:oskyar,項目名稱:Sistemas-Multimedia,代碼行數:26,代碼來源:VentanaInternaGrabador.java

示例11: VentanaInternaReproductor

import javax.sound.sampled.LineListener; //導入依賴的package包/類
public VentanaInternaReproductor(File f) {
    initComponents();

    player = new SMSoundPlayerRecorder(f);
    this.setTitle(f.getName());
    LineListener lineListener = new LineListener() {
        @Override
        public void update(LineEvent event) {
            if (event.getType() == Type.START) {
                play.setEnabled(false);
                stop.setEnabled(true);
            }
            if (event.getType() == Type.STOP) {
                play.setEnabled(true);
                play.setSelected(false);
                stop.setEnabled(false);
            }
        }
    };
    ((SMSoundPlayerRecorder)player).setLineListener(lineListener);
    this.pack();
}
 
開發者ID:oskyar,項目名稱:Sistemas-Multimedia,代碼行數:23,代碼來源:VentanaInternaReproductor.java

示例12: VentanaInternaGrabador

import javax.sound.sampled.LineListener; //導入依賴的package包/類
public VentanaInternaGrabador() {
    initComponents();
    exist=true;
    recorder = new SMSoundPlayerRecorder(new File("nuevo"));
    LineListener lineListener = new LineListener() {
        @Override
        public void update(LineEvent event) {
            if (event.getType() == Type.START) {
                recorderButton.setEnabled(false);
                stopButton.setEnabled(true);
            }
            if (event.getType() == Type.STOP) {
                recorderButton.setEnabled(true);
                stopButton.setEnabled(false);
            }

        }
    };
    ((SMSoundPlayerRecorder) recorder).setLineListener(lineListener);
    this.pack();
}
 
開發者ID:oskyar,項目名稱:Sistemas-Multimedia,代碼行數:22,代碼來源:VentanaInternaGrabador.java

示例13: VentanaInternaReproductor

import javax.sound.sampled.LineListener; //導入依賴的package包/類
public VentanaInternaReproductor(File f) {
    initComponents();
    if (f != null) {
        player = new SMSoundPlayer(f);
        this.setTitle(f.getName());
        LineListener lineListener = new LineListener() {
            @Override
            public void update(LineEvent event) {
                if (event.getType() == Type.START) {
                    play.setEnabled(false);
                    stop.setEnabled(true);
                }
                if (event.getType() == Type.STOP) {
                    play.setEnabled(true);
                    play.setSelected(false);
                    stop.setEnabled(false);
                }
            }
        };
        ((SMSoundPlayer) player).setLineListener(lineListener);
        this.pack();
    }
}
 
開發者ID:oskyar,項目名稱:Sistemas-Multimedia,代碼行數:24,代碼來源:VentanaInternaReproductor.java

示例14: JSAudio

import javax.sound.sampled.LineListener; //導入依賴的package包/類
JSAudio(AudioInputStream as) throws LineUnavailableException, IOException {
    Mixer mix = AudioIO.findMixer(as.getFormat());
    clip = (Clip) (mix != null ? mix.getLine(new Line.Info(Clip.class)) : AudioSystem.getLine(new Line.Info(Clip.class)));
    clip.open(as);
    clip.addLineListener(new LineListener() {
        public void update(LineEvent event) {
            if (loop && event.getType() == Type.STOP) {
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        clip.start();
                    }
                });
            }
        }
    });
}
 
開發者ID:IvyBits,項目名稱:Amber-IDE,代碼行數:17,代碼來源:JSAudio.java

示例15: JSAudioRecordingClip

import javax.sound.sampled.LineListener; //導入依賴的package包/類
JSAudioRecordingClip(Clip clip, AudioMetaData mdata)
{
	c = clip;
	// because Clip doesn't give access to the loop count
	// we just loop it ourselves by triggering off of a STOP event
	c.addLineListener( new LineListener()
	{
		public void update(LineEvent event)
		{
			if ( event.getType().equals( LineEvent.Type.STOP ) )
			{
				if ( playing && loopCount != 0 )
				{
					c.setMicrosecondPosition( 0 );
					c.start();
					if ( loopCount > 0 )
					{
						loopCount--;
					}
				}
				else
				{
					playing = false;
				}
			}
		}
	} );
	playing = false;
	loopCount = 0;
	meta = mdata;
}
 
開發者ID:JacobRoth,項目名稱:romanov,代碼行數:32,代碼來源:JSAudioRecordingClip.java


注:本文中的javax.sound.sampled.LineListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。