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


Java LineEvent類代碼示例

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


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

示例1: play

import javax.sound.sampled.LineEvent; //導入依賴的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: setOpen

import javax.sound.sampled.LineEvent; //導入依賴的package包/類
/**
 * This method sets the open state and generates
 * events if it changes.
 */
final void setOpen(boolean open) {

    if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ")  this.open: " + this.open);

    boolean sendEvents = false;
    long position = getLongFramePosition();

    synchronized (this) {
        if (this.open != open) {
            this.open = open;
            sendEvents = true;
        }
    }

    if (sendEvents) {
        if (open) {
            sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
        } else {
            sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
        }
    }
    if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ")  this.open: " + this.open);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:AbstractLine.java

示例3: setStarted

import javax.sound.sampled.LineEvent; //導入依賴的package包/類
/**
 * This method sets the started state and generates
 * events if it changes.
 */
final void setStarted(boolean started) {

    if (Printer.trace) Printer.trace("> AbstractDataLine: setStarted(" + started + ")");

    boolean sendEvents = false;
    long position = getLongFramePosition();

    synchronized (this) {

        if (this.started != started) {
            this.started = started;
            sendEvents = true;
        }
    }

    if (sendEvents) {

        if (started) {
            sendEvents(new LineEvent(this, LineEvent.Type.START, position));
        } else {
            sendEvents(new LineEvent(this, LineEvent.Type.STOP, position));
        }
    }
    if (Printer.trace) Printer.trace("< AbstractDataLine: setStarted completed");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:AbstractDataLine.java

示例4: test

import javax.sound.sampled.LineEvent; //導入依賴的package包/類
private static void test(final AudioFormat format, final byte[] data)
        throws Exception {
    final Line.Info info = new DataLine.Info(Clip.class, format);
    final Clip clip = (Clip) AudioSystem.getLine(info);

    go = new CountDownLatch(1);
    clip.addLineListener(event -> {
        if (event.getType().equals(LineEvent.Type.START)) {
            go.countDown();
        }
    });

    clip.open(format, data, 0, data.length);
    clip.start();
    go.await();
    while (clip.isRunning()) {
        // This loop should not hang
    }
    while (clip.isActive()) {
        // This loop should not hang
    }
    clip.close();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:IsRunningHang.java

示例5: update

import javax.sound.sampled.LineEvent; //導入依賴的package包/類
public void update(LineEvent e) {
    if (e.getType() == LineEvent.Type.STOP) {
        stopOccured++;
        out("  Test program: receives STOP event for clip="+clip.toString()+" no."+stopOccured);
        out("  Test program: Calling close() in event dispatcher thread");
        clip.close();
        synchronized (lock) {
            lock.notifyAll();
        }
    }
    else if (e.getType() == LineEvent.Type.CLOSE) {
        out("  Test program: receives CLOSE event for "+clip.toString());
        synchronized (lock) {
            lock.notifyAll();
        }
    }
    else if (e.getType() == LineEvent.Type.START) {
        out("  Test program: receives START event for "+clip.toString());
    }
    else if (e.getType() == LineEvent.Type.OPEN) {
        out("  Test program: receives OPEN event for "+clip.toString());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:ClipLinuxCrash2.java

示例6: playAudio

import javax.sound.sampled.LineEvent; //導入依賴的package包/類
public void playAudio(float volumeDelta) {
	boolean isPlaying = false;
	
	if(clip != null)
		if(clip.isActive())
			isPlaying = true;
	
	
	if(!shouldPreloadAudio && !isPlaying) {
		loadClip();
		
		clip.addLineListener((LineEvent event) -> {
			if(event.getType() == LineEvent.Type.STOP)
				clip.close();
		});
	}
	
	
	float newVolume = Math.max(Math.min(volumeAdjustment + volumeDelta, volume.getMaximum()), volume.getMinimum());
	volume.setValue(newVolume);
	
	clip.setFramePosition(0);
	clip.start();
}
 
開發者ID:ProjectK47,項目名稱:Mafia,代碼行數:25,代碼來源:AudioClip.java

示例7: open

import javax.sound.sampled.LineEvent; //導入依賴的package包/類
@Override
public void open() throws AudioException {

	try {
		
		this.audioInputStream = Audio.getAudioInputStream(this.resource);
		this.clip = AudioSystem.getClip();
		this.clip.open(this.audioInputStream);
		this.clip.addLineListener(event -> {
			
			if(event.getType().equals(LineEvent.Type.STOP) && this.clip.getMicrosecondPosition() >= this.clip.getMicrosecondLength()) {
				
				this.trigger(AudioEvent.Type.REACHED_END);
			}
		});
		this.controls = AbstractAudio.extractControls(this.clip, this.controls);
		this.open = true;
		this.trigger(AudioEvent.Type.OPENED);
		
	} catch(Exception exception) {
		
		throw new AudioException(exception);
	}
}
 
開發者ID:RalleYTN,項目名稱:SimpleAudio,代碼行數:25,代碼來源:BufferedAudio.java

示例8: playSound

import javax.sound.sampled.LineEvent; //導入依賴的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

示例9: openClip

import javax.sound.sampled.LineEvent; //導入依賴的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

示例10: setPlayer

import javax.sound.sampled.LineEvent; //導入依賴的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

示例11: update

import javax.sound.sampled.LineEvent; //導入依賴的package包/類
public void update(LineEvent event) {
	// ストップか最後まで再生された場合
	if(event.getType() == LineEvent.Type.STOP) {
		Clip clip = (Clip) event.getSource();
		clip.stop();
		clip.setFramePosition(0); // 再生位置を最初に戻す
	}
}
 
開發者ID:PoochyEXE,項目名稱:nullpomino,代碼行數:9,代碼來源:WaveEngine.java

示例12: playSirenSound

import javax.sound.sampled.LineEvent; //導入依賴的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

示例13: setOpen

import javax.sound.sampled.LineEvent; //導入依賴的package包/類
/**
 * This method sets the open state and generates
 * events if it changes.
 */
protected void setOpen(boolean open) {

    if (Printer.trace) Printer.trace("> "+getClass().getName()+" (AbstractLine): setOpen(" + open + ")  this.open: " + this.open);

    boolean sendEvents = false;
    long position = getLongFramePosition();

    synchronized (this) {
        if (this.open != open) {
            this.open = open;
            sendEvents = true;
        }
    }

    if (sendEvents) {
        if (open) {
            sendEvents(new LineEvent(this, LineEvent.Type.OPEN, position));
        } else {
            sendEvents(new LineEvent(this, LineEvent.Type.CLOSE, position));
        }
    }
    if (Printer.trace) Printer.trace("< "+getClass().getName()+" (AbstractLine): setOpen(" + open + ")  this.open: " + this.open);
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:28,代碼來源:AbstractLine.java

示例14: playAudio

import javax.sound.sampled.LineEvent; //導入依賴的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

示例15: update

import javax.sound.sampled.LineEvent; //導入依賴的package包/類
public void update(LineEvent event) {
	if (event.getType() == LineEvent.Type.OPEN) {
		// start the line, init the buffer
		line.start();
		
		int bytes = line.getBufferSize();
		byteBuf = new byte [bytes];
		doubleBuf = new double [bytes / af.getFrameSize()];
		fs = af.getFrameSize();
		
		lineOpened = true;
	} else if (event.getType() == LineEvent.Type.START) {
		// nothing to do here
	} else if (event.getType() == LineEvent.Type.STOP) {
		line.close();
	} else if (event.getType() == LineEvent.Type.CLOSE) {
		// only free the line now
		lineOpened = false;
	} else
		System.err.println("Unknown LineEvent: " + event.getType());
	
}
 
開發者ID:lendlice,項目名稱:crowdpp,代碼行數:23,代碼來源:AudioPlay.java


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