KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ixenon > free > util > SingleAudioPlayer


1 /* $Id$
2  *
3  * Copyright (c) 1999 Xenonsoft Limited. All Rights Reserved.
4  *
5  * This software is protected by copyright. You are hereby notified from
6  * now by reading this message. This software is also the confidential
7  * and proprietary information of Xenonsoft Limited. ("Confidential
8  * Information").
9  *
10  * This software is distributed under the Xenonsoft Public end user
11  * License ("XPeL"), where the machine-readable source code is provided
12  * under the "Open Source" model.
13  * For more information, please read the file "LICENSE-XPL.txt"
14  */

15
16 // SingleAudioPlayer.java
17

18 //
19
// Description:
20
// SingleAudioPlayer designed to play only ONE sound.hold an applications
21
//
22
// Author:
23
// Peter Pilgrim
24
// Fri Jul 31 00:46:52 BST 1998
25
//
26
// RCS HEADER ``SingleAudioPlayer.java''
27
//
28
// $Author$
29
// $Date$
30
// $Source$
31
// $Revision$ $State$ $Locker$
32
//
33
// History
34
// ================================================================================
35
// $Log$
36
//
37

38 package ixenon.free.util;
39
40 import sun.audio.*; // Sun Audio Classes non-standard!
41

42 import java.io.*; // I/O Streams
43
import java.net.*; // URL
44

45 public class SingleAudioPlayer {
46
47     InputStream last_audiostream; // saved audio stream
48
boolean bfLooping = false;
49     
50     public SingleAudioPlayer() {}
51     
52     /** plays an audio stream sequence */
53     public void play (AudioData audioData)
54     {
55     stop();
56     AudioDataStream audiostream = new AudioDataStream( audioData );
57     last_audiostream = audiostream;
58     AudioPlayer.player.start(audiostream);
59     }
60
61     /** plays an sequence of audio clips */
62     public void play (AudioStreamSequence sequence )
63     {
64     stop();
65     last_audiostream = sequence;
66     AudioPlayer.player.start(sequence);
67     }
68
69     /** plays continuously an audio data clip */
70     public void loop (AudioData audioData)
71     {
72     stop();
73     ContinuousAudioDataStream contstream = new ContinuousAudioDataStream( audioData );
74     last_audiostream = contstream;
75     bfLooping = true;
76     AudioPlayer.player.start(contstream);
77     }
78
79     /** stops the last audio data clip, which is now playing */
80     public void stop()
81     {
82     if (last_audiostream != null) {
83         AudioPlayer.player.stop(last_audiostream);
84         last_audiostream = null;
85         bfLooping = false;
86     }
87     }
88
89     public boolean isPlaying()
90     {
91     return (last_audiostream != null);
92     }
93
94     public boolean isLooping()
95     {
96     return (last_audiostream != null && bfLooping);
97     }
98
99 }
100
101 // fini
102
Popular Tags