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


Java AudioClip類代碼示例

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


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

示例1: playApplet

import java.applet.AudioClip; //導入依賴的package包/類
private static void playApplet(String filename) {
	URL url = null;
	try {
		File file = new File(filename);
		if (file.canRead())
			url = file.toURI().toURL();
	} catch (MalformedURLException e) {
		throw new IllegalArgumentException("could not play '" + filename + "'", e);
	}

	// URL url = StdAudio.class.getResource(filename);
	if (url == null) {
		throw new IllegalArgumentException("could not play '" + filename + "'");
	}

	AudioClip clip = Applet.newAudioClip(url);
	clip.play();
}
 
開發者ID:Scoutdrago3,項目名稱:MusicToGraph,代碼行數:19,代碼來源:StdAudio.java

示例2: myKeyEvent

import java.applet.AudioClip; //導入依賴的package包/類
public Command myKeyEvent(KeyStroke stroke) {
  myGetKeyCommands();
  Command c = null;
  if (command.matches(stroke)) {
    final String clipName = format.getText(Decorator.getOutermost(this));
    c = new PlayAudioClipCommand(clipName);
    try {
      final AudioClip clip = GameModule.getGameModule()
                                       .getDataArchive()
                                       .getCachedAudioClip(clipName);
      if (clip != null) {
        clip.play();
      }
    }
    catch (IOException e) {
      reportDataError(this, Resources.getString("Error.not_found", "Audio Clip"), "Clip="+clipName, e);
    }
  }
  return c;
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:21,代碼來源:PlaySound.java

示例3: TravoltageAudio

import java.applet.AudioClip; //導入依賴的package包/類
public TravoltageAudio( TravoltageModel travoltageModel ) {
    travoltageModel.addListener( new TravoltageModel.Listener() {
        public void sparkStarted() {
        }

        public void sparkFinished() {
            sparkFinished = true;
        }

        public void electronExitedFinger() {
            if( sparkFinished ) {
                play();
                sparkFinished = false;
            }
        }
    } );
    AudioClip ouch = Applet.newAudioClip( findResource( "travoltage/audio/OuchSmallest.wav" ) );
    AudioClip zzt = Applet.newAudioClip( findResource( "travoltage/audio/ShockSmallest.wav" ) );
    this.clips = new AudioClip[]{ouch, zzt};
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:21,代碼來源:TravoltageAudio.java

示例4: playApplet

import java.applet.AudioClip; //導入依賴的package包/類
private static void playApplet(String filename) {
    URL url = null;
    try {
        File file = new File(filename);
        if(file.canRead()) url = file.toURI().toURL();
    }
    catch (MalformedURLException e) {
        throw new IllegalArgumentException("could not play '" + filename + "'", e);
    }

    // URL url = StdAudio.class.getResource(filename);
    if (url == null) {
        throw new IllegalArgumentException("could not play '" + filename + "'");
    }

    AudioClip clip = Applet.newAudioClip(url);
    clip.play();
}
 
開發者ID:yimng,項目名稱:personal-stuff,代碼行數:19,代碼來源:StdAudio.java

示例5: getJButton

import java.applet.AudioClip; //導入依賴的package包/類
/**
 * This method initializes jButton
 * 
 * @return javax.swing.JButton
 */
private JButton getJButton() {
    if (jButton == null) {
        jButton = new JButton();
        jButton.setText("Add");
        jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                File sound = new File("bddbddb.wav");
                try {
                    AudioClip audioClip = Applet.newAudioClip(sound.toURL());
                    audioClip.play();
                } catch (MalformedURLException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
        });
    }
    return jButton;
}
 
開發者ID:petablox-project,項目名稱:petablox,代碼行數:25,代碼來源:SolverGUI.java

示例6: getFunDialog

import java.applet.AudioClip; //導入依賴的package包/類
public static Dialog getFunDialog()   {
    FileObject img = FileUtil.getConfigFile("BartGIfImage/BartSaturdayNightFever.gif");
    FileObject audio = FileUtil.getConfigFile("BartAudio/STheme.wav");
    final AudioClip clip = Applet.newAudioClip(audio.toURL());
    Icon icon = new ImageIcon(img.toURL());   
    JLabel label = new JLabel(icon);
    final Dialog dialog = new BartThemeDialog(WindowManager.getDefault().getMainWindow(), label);
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if(e.getClickCount() == 1)   {
                clip.stop();
                dialog.dispose();
            }
        }
        
    });
    clip.loop();
    return dialog;
}
 
開發者ID:dbunibas,項目名稱:BART,代碼行數:22,代碼來源:BartThemeDialog.java

示例7: playSound

import java.applet.AudioClip; //導入依賴的package包/類
/**
 * Work method to play the sound.
 */
protected Object playSound(String soundToPlay) {
	// Load it from the cache.
	AudioClip clip = (AudioClip)soundCache.get(soundToPlay);
	
	// Construct a new AudioClip and cache it.
	if (clip == null) {
		try{
			clip = Applet.newAudioClip(ClassLoader.getSystemResource(soundToPlay));
			soundCache.put(soundToPlay, clip);
		} catch (NullPointerException npe){
		} catch (NoSuchMethodError nsme){
		}
	}
	
	// If the clip was somehow properly constructed or retrieved from the cache, play it.
	if (clip != null) {
		clip.play();
	}
	
	return "done";
}
 
開發者ID:bvarner,項目名稱:javashare,代碼行數:25,代碼來源:ApplicationSoundThreadManager.java

示例8: playSound

import java.applet.AudioClip; //導入依賴的package包/類
/**
 * Plays the Sound, constructing the clip from the Applet passed to the constructor.
 * @overrides ApplicationSoundThreadManager.playSound
 */
protected Object playSound(String soundToPlay) {
	// Load it from the cache.
	AudioClip clip = (AudioClip)soundCache.get(soundToPlay);
	
	// Construct a new AudioClip and cache it.
	if (clip == null) {
		try{
			clip = soundSource.getAudioClip(new URL(soundSource.getParameter("SoundDirURL") + "/" + soundToPlay));
			soundCache.put(soundToPlay, clip);
		} catch (NullPointerException npe){
		} catch (NoSuchMethodError nsme){
		} catch (MalformedURLException mue){
			System.out.println(mue.toString());
		}
	}
	
	// If the clip was somehow properly constructed or retrieved from the cache, play it.
	if (clip != null) {
		clip.play();
	}
	
	return "done";
}
 
開發者ID:bvarner,項目名稱:javashare,代碼行數:28,代碼來源:AppletSoundThreadManager.java

示例9: BarriersSelector

import java.applet.AudioClip; //導入依賴的package包/類
/**
 * construct method . <br />
 * 
 * @param	default
 * @param	max
 * @param	offset
 * @param	w
 * @param	h
 * @param	icons
 */
public BarriersSelector( Battlefield bf, int defualt,
		int max, int offset, int w, int h, ImageIcon[] icons, AudioClip buttonClip ) 
{
	this.BF = bf;
	this.barriers = defualt;
	this.max = max;
	this.offset = offset;
	this.w = w;
	this.h = h;
	this.tImages = icons[0].getImage();
	this.pImages = icons[1].getImage();
	this.grass = icons[2];
	this.buttonClip = buttonClip;
	i_width = icons[0].getIconWidth();
	i_height = icons[0].getIconHeight();
	
	str_width = max * this.offset;
}
 
開發者ID:niluzhang,項目名稱:TankWar,代碼行數:29,代碼來源:BarriersSelector.java

示例10: playClip

import java.applet.AudioClip; //導入依賴的package包/類
/**
 * Plays an AudioClip.
 *
 * @param clip the audioclip to play.
 */
public void playClip(final AudioClip clip) {

    final Runnable playThread = new Runnable() {
        public void run() {
            try {
                clip.play();
            }
            catch (Exception ex) {
                System.err.println("Unable to load sound file");
            }
        }
    };

    TaskEngine.getInstance().submit(playThread);
}
 
開發者ID:visit,項目名稱:spark-svn-mirror,代碼行數:21,代碼來源:SoundManager.java

示例11: getAudio

import java.applet.AudioClip; //導入依賴的package包/類
public static AudioClip getAudio(int index) {
	if (audios[index] == null) {
		URL url = null;
		ClassLoader classLoader = FileHelper.class.getClassLoader();
		url = classLoader.getResource("music/" + index + ".wav");
		audios[index] = Applet.newAudioClip(url);
	}
	return audios[index];
}
 
開發者ID:zhangjikai,項目名稱:LinkGame,代碼行數:10,代碼來源:EffectSound.java

示例12: createAudioClipFactory

import java.applet.AudioClip; //導入依賴的package包/類
protected AudioClipFactory createAudioClipFactory() {
  return new AudioClipFactory() {
    public AudioClip getAudioClip(URL url) {
      return Applet.newAudioClip(url);
    }
  };
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:8,代碼來源:SoundConfigurer.java

示例13: playSound

import java.applet.AudioClip; //導入依賴的package包/類
/**
 * Plays a sound based on
 * the type parameter.
 * @param type the sound type defined in
 * Notification class.
 */
public void playSound(SoundType type) {
    final AudioClip aClip = config.getSound(type);
    if (aClip != null) {
        aClip.play();
    }
}
 
開發者ID:adbenitez,項目名稱:jNotifyOSD,代碼行數:13,代碼來源:DesktopNotify.java

示例14: getSound

import java.applet.AudioClip; //導入依賴的package包/類
public AudioClip getSound(SoundType sound) {
    if (sounds == null) {
        SoundType[] soundsT = SoundType.values();
        sounds = new HashMap<SoundType, AudioClip>();
        String urlSound;
        URL url;
        for (SoundType st : soundsT) {
            urlSound = sounds_path + st.name() + ".wav";
            url = getClass().getResource(urlSound);
            if (url == null) {
                switch (st) {
                case ERROR:
                    urlSound = sounds_path + SoundType.WARNING.name() + ".wav";
                    url = getClass().getResource(urlSound);
                    break;
                case WARNING:
                    urlSound = sounds_path + SoundType.ERROR.name() + ".wav";
                    url = getClass().getResource(urlSound);
                    break;
                default: // do nothing
                }
                if (url == null) {
                    urlSound = sounds_path + SoundType.MESSAGE.name() + ".wav";
                    url = getClass().getResource(urlSound);
                }
            }
            if (url != null) {
                sounds.put(st, Applet.newAudioClip(url));
            }
        }
    }
    return sounds.get(sound);
}
 
開發者ID:adbenitez,項目名稱:jNotifyOSD,代碼行數:34,代碼來源:NotifyConfig.java

示例15: getAudioClip

import java.applet.AudioClip; //導入依賴的package包/類
public AudioClip getAudioClip(URL url) {
    // We don't currently support audio clips in the Beans.instantiate
    // applet context, unless by some luck there exists a URL content
    // class that can generate an AudioClip from the audio URL.
    try {
        return (AudioClip) url.getContent();
    } catch (Exception ex) {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:11,代碼來源:Beans.java


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