当前位置: 首页>>代码示例>>Java>>正文


Java Clip类代码示例

本文整理汇总了Java中javax.sound.sampled.Clip的典型用法代码示例。如果您正苦于以下问题:Java Clip类的具体用法?Java Clip怎么用?Java Clip使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Clip类属于javax.sound.sampled包,在下文中一共展示了Clip类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDefaultProvider

import javax.sound.sampled.Clip; //导入依赖的package包/类
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:JDK13Services.java

示例2: play

import javax.sound.sampled.Clip; //导入依赖的package包/类
/**
	 * This method allows to actually play the sound provided from the
	 * {@link #audioInputStream}
	 * 
	 * @throws LineUnavailableException
	 *             if the {@link Clip} object can't be created
	 * @throws IOException
	 *             if the audio file can't be find
	 */
	protected void play() throws LineUnavailableException, IOException {
//		Clip clip = AudioSystem.getClip();
		Clip clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));
		clip.addLineListener(listener);
		clip.open(audioInputStream);
		try {
			clip.start();
			listener.waitUntilDone();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			clip.close();
		}
		audioInputStream.close();
	}
 
开发者ID:thahn0720,项目名称:agui_framework,代码行数:25,代码来源:AchievementSound.java

示例3: ExtendedClip

import javax.sound.sampled.Clip; //导入依赖的package包/类
public ExtendedClip(JuggleMasterPro objPjuggleMasterPro, byte bytPsoundFileIndex) {

		this.bytGsoundFileIndex = bytPsoundFileIndex;
		try {
			final AudioInputStream objLaudioInputStream =
															AudioSystem.getAudioInputStream(new File(Strings.doConcat(	objPjuggleMasterPro.strS_CODE_BASE,
																														Constants.strS_FILE_NAME_A[Constants.intS_FILE_FOLDER_SOUNDS],
																														objPjuggleMasterPro.chrGpathSeparator,
																														Constants.strS_FILE_SOUND_NAME_A[bytPsoundFileIndex])));
			final AudioFormat objLaudioFormat = objLaudioInputStream.getFormat();
			final DataLine.Info objLdataLineInfo =
													new DataLine.Info(Clip.class, objLaudioFormat, (int) objLaudioInputStream.getFrameLength()
																									* objLaudioFormat.getFrameSize());
			this.objGclip = (Clip) AudioSystem.getLine(objLdataLineInfo);
			this.objGclip.open(objLaudioInputStream);
		} catch (final Throwable objPthrowable) {
			Tools.err("Error while initializing sound : ", Constants.strS_FILE_SOUND_NAME_A[bytPsoundFileIndex]);
			this.objGclip = null;
		}
	}
 
开发者ID:jugglemaster,项目名称:JuggleMasterPro,代码行数:21,代码来源:ExtendedClip.java

示例4: run

import javax.sound.sampled.Clip; //导入依赖的package包/类
/**
 * The sound is load and play in a thread no slow down the engine.
 * */
@Override
public void run() {
    try {
        InputStream in = new BufferedInputStream(this.getClass().getResourceAsStream(this.filename + ".wav"));
        Clip clip = AudioSystem.getClip();

        clip.open(AudioSystem.getAudioInputStream(in));
        if (this.loop){
            clip.loop(Clip.LOOP_CONTINUOUSLY);
        }
        clip.start();
    }catch (Exception e){
        System.err.println(e);
    }

}
 
开发者ID:Exia-Aix-A2,项目名称:Boulder-Dash,代码行数:20,代码来源:Sound.java

示例5: getDefaultProvider

import javax.sound.sampled.Clip; //导入依赖的package包/类
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class<?> typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:JDK13Services.java

示例6: test

import javax.sound.sampled.Clip; //导入依赖的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

示例7: doMixerClip

import javax.sound.sampled.Clip; //导入依赖的package包/类
private static void doMixerClip(Mixer mixer, AudioFormat format) {
    if (mixer==null) return;
    try {
        System.out.println("Clip from mixer "+mixer+":");
        System.out.println("   "+mixer.getMixerInfo());
            DataLine.Info info = new DataLine.Info(
                                      Clip.class,
                                      format);

        if (mixer.isLineSupported(info)) {
            Clip clip = (Clip) mixer.getLine(info);
            doLine1(clip, format);
        } else {
            System.out.println("  - Line not supported");
        }
    } catch (Throwable t) {
        System.out.println("  - Caught exception. Not failed.");
        System.out.println("  - "+t.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:LineDefFormat.java

示例8: playSound

import javax.sound.sampled.Clip; //导入依赖的package包/类
private synchronized void playSound(final String audioFileName) {
	if(isSoundEnabled) {
		try {
			Clip clip = AudioSystem.getClip();
			InputStream inputStream = MainWindow.class.getResourceAsStream(audioFileName);
			if(inputStream != null) {
				AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);
				clip.open(audioInputStream);
				clip.start();
			}
			else {
				System.out.println("Input stream not valid");
			}
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:cyberpirate92,项目名称:snake-game,代码行数:20,代码来源:MainWindow.java

示例9: loadSound

import javax.sound.sampled.Clip; //导入依赖的package包/类
/**
 * WAV files only
 * 
 * @param name
 *            Name to store sound as
 * @param file
 *            Sound file
 */
public static void loadSound(String name, String file) {
	try {
		System.out.print("Loading sound file: \"" + file + "\" into clip: \"" + name + "\", ");
		BufferedInputStream in = new BufferedInputStream(SoundPlayer.class.getResourceAsStream(file));
		AudioInputStream ain = AudioSystem.getAudioInputStream(in);

		Clip c = AudioSystem.getClip();
		c.open(ain);
		c.setLoopPoints(0, -1);
		clips.put(name, c);
		ain.close();
		in.close();
		System.out.println("Done.");
	} catch (Exception e) {
		System.out.println("Failed. (" + e.getMessage() + ")");
	}
}
 
开发者ID:Keabot-Studios,项目名称:Caritemere,代码行数:26,代码来源:SoundPlayer.java

示例10: start

import javax.sound.sampled.Clip; //导入依赖的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

示例11: destroy

import javax.sound.sampled.Clip; //导入依赖的package包/类
/**
 * Destroys the MultiClip and releases all resources.
 */
public void destroy() {
	if (clips.size() > 0) {
		for (Clip c : clips) {
			c.stop();
			c.flush();
			c.close();
		}
		extraClips -= clips.size() - 1;
		clips = new LinkedList<Clip>();
	}
	audioData = null;
	if (audioIn != null) {
		try {
			audioIn.close();
		} catch (IOException e) {
			explode(String.format("Could not close AudioInputStream for MultiClip %s.", name), e,
				DEFAULT_OPTIONS);
		}
	}
}
 
开发者ID:yugecin,项目名称:opsu-dance,代码行数:24,代码来源:MultiClip.java

示例12: mute

import javax.sound.sampled.Clip; //导入依赖的package包/类
/**
* Mute the Clip (because destroying it, won't stop it)
*/
public void mute() {
	try {
		Clip c = getClip();
		if (c == null) {
			return;
		}
		float val = (float) (Math.log(Float.MIN_VALUE) / Math.log(10.0) * 20.0);
		if (val < -80.0f) {
			val = -80.0f;
		}
		((FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN)).setValue(val);
	} catch (IllegalArgumentException ignored) {
	} catch (LineUnavailableException e) {
		e.printStackTrace();
	}
}
 
开发者ID:yugecin,项目名称:opsu-dance,代码行数:20,代码来源:MultiClip.java

示例13: playButtonClickNormalSound

import javax.sound.sampled.Clip; //导入依赖的package包/类
/** Play the audio clip when regular button is clicked. */
public void playButtonClickNormalSound()
{
	try
	{
		String soundName = "regular_button_click_sound.wav";    
		AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(soundName).getAbsoluteFile());
		Clip clip = AudioSystem.getClip();
		clip.open(audioInputStream);
		clip.setFramePosition(0);
		clip.start();
	}
	catch (Exception e)
	{
		
	}
}
 
开发者ID:Meerkat007,项目名称:Java-Swing-Projects,代码行数:18,代码来源:a1.java

示例14: main

import javax.sound.sampled.Clip; //导入依赖的package包/类
public static void main(String[] args) {
    new Thread(() -> {
        while (true) {
            int delay = (RANDOM.nextInt(MAX_DELAY_SECONDS - MIN_DELAY_SECONDS) + MIN_DELAY_SECONDS) * 1000;
            try (
                    ByteArrayInputStream bais = new ByteArrayInputStream(AUDIO_BYTES);
                    AudioInputStream audioIn = AudioSystem.getAudioInputStream(bais);
            ) {
                Clip clip = AudioSystem.getClip();
                clip.open(audioIn);

                Thread.currentThread().sleep(delay);
                clip.start();
            } catch (InterruptedException | IOException | LineUnavailableException
                    | UnsupportedAudioFileException ex) {
                ex.printStackTrace();
            }
        }
    }).start();
}
 
开发者ID:caseif,项目名称:binks.jar,代码行数:21,代码来源:Binks.java

示例15: play

import javax.sound.sampled.Clip; //导入依赖的package包/类
private void play(String wavPath, float db) {
    if (!dnd && db > -40) {
        ClassLoader classLoader = getClass().getClassLoader();
        try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) {
            Clip clip = AudioSystem.getClip();
            clip.open(stream);
            if (db != 0.0) {
                FloatControl gainControl =
                        (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
                gainControl.setValue(db);
            }
            clip.start();
        } catch (Exception e) {
            logger.error("Cannot start playing wav file: ", e);
        }
    }
}
 
开发者ID:Exslims,项目名称:MercuryTrade,代码行数:18,代码来源:SoundNotifier.java


注:本文中的javax.sound.sampled.Clip类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。