`
- 浏览:
17306 次
- 性别:
- 来自:
上海
-
java 代码
- import java.io.IOException;
- import java.net.MalformedURLException;
-
- import javax.media.ControllerEvent;
- import javax.media.ControllerListener;
- import javax.media.EndOfMediaEvent;
- import javax.media.Manager;
- import javax.media.MediaLocator;
- import javax.media.NoPlayerException;
- import javax.media.Player;
- import javax.media.Time;
-
- public class SimplePlayer implements ControllerListener {
-
-
- Player player = null;
-
- public synchronized void controllerUpdate(ControllerEvent event) {
-
- if (player == null)
- return;
-
- if (event instanceof EndOfMediaEvent) {
- player.setMediaTime(new Time(0));
-
- }
- }
-
- public SimplePlayer() {
-
- String mediaFile = "file:\\D:\\tencent\\qq\\tmsound\\Global.wav";
- MediaLocator mrl = null;
-
- try {
-
- if ((mrl = new MediaLocator(mediaFile)) == null)
- Fatal("Can't build URL for " + mediaFile);
-
-
- try {
- player = Manager.createPlayer(mrl);
- } catch (NoPlayerException e) {
- System.out.println(e);
- Fatal("Could not create player for " + mrl);
- }
-
- player.addControllerListener(this);
-
- } catch (MalformedURLException e) {
- Fatal("Invalid media file URL!");
- } catch (IOException e) {
- Fatal("IO exception creating player for " + mrl);
- }
-
- }
-
- public void start() {
- if (player != null)
- player.start();
- }
-
- void Fatal(String s) {
- System.err.println("FATAL ERROR: " + s);
- throw new Error(s);
- }
-
- public static void main(String[] args) throws Exception {
- SimplePlayer sp = new SimplePlayer();
- sp.start();
- }
- }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
1.Mastering the fundamentals of coding Java for Android. 2.Installing and setting up your Android development environment. 3.Building functional user interfaces with the Android Studio visual designer...
1.Mastering the fundamentals of coding Java for Android. 2.Installing and setting up your Android development environment. 3.Building functional user interfaces with the Android Studio visual designer...
总结来说,"Runtime.rar"中的"Play a music with java"主题涵盖了Java运行时环境、Java Sound API的使用、异常处理等多个知识点。理解这些内容有助于开发者编写出功能丰富的Java应用程序,包括多媒体处理在内的一...
4. **音频处理API**:Java Media Framework (JMF) 或 Java Sound API 可能被用到了ubmp3play中,这些API提供了读取、解码和播放音频文件的能力。开发者可以通过它们来控制音量、播放、暂停和停止MP3文件。 5. **...
package soundsystem; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework....
This chapter covers four different ways to play sound, how to display waveforms, and how to embed MP3 support in your own programs. Chapter 11, Native Integration and Packaging The best software ...
This book offers a step-by-step Android game development guide that's easy to follow with practical tips, illustrations, diagrams, and images, including a full game project explained gradually in each...
create Silverlight pages that have interactive graphics, use vector animations, and play video and sound files. If this all sounds eerily familiar, it’s because the same trick has been tried before. ...
With Sound ) A Very Cute Screen Saver ,with source code, If you want more avi files then please mail me.<END><br>36 , superwriter.zip A complete Wordprocessor, with source code. You can save, open ...
这个是合集~一般是这里最全的了 另外加的 PDF是英文的 .......中文白皮书.pdf Quota RCS-...
Random Big Rich Man(瑞德大富翁) is monopoly-like game using random map to play. It's local game with 4 AI/Human player. Install precondition: Install java 1.8.0 Image or sound from below project or...