summaryrefslogtreecommitdiffstats
path: root/qtjava/javalib/examples/sound/SoundPlayer.java
blob: 73d54b7131c3172ed3a71fca763b9927539e2285 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/***************************************************************************
* $Id$
**
* Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
* This file is part of an example program for Qt.  This example
* program may be used, distributed and modified without limitation.
**
****************************************************************************/

import org.trinitydesktop.qt.*;


class SoundPlayer  extends TQMainWindow {

private    TQSound bucket3;
private    TQSound bucket4;

//
// Very simple example of TQSound.play(filename)
//
// 99% of this program is just boilerplate Qt code to put up a nice
// window so you think something special is happening.
//


SoundPlayer()
{
    super();
    bucket3 = new TQSound("sounds/3.wav");
    bucket4 = new TQSound("sounds/4.wav");
    
	if (!TQSound.isAvailable()) {
	// Bail out.  Programs in which sound is not critical
	// could just silently (hehe) ignore the lack of a server.
	//
	TQMessageBox.warning(this,"No Sound",
		"<p><b>Sorry, you are not running the Network Audio System.</b>"
		+ "<p>If you have the `au' command, run it in the background before this program. "
		+ "The latest release of the Network Audio System can be obtained from:"
		+ "<pre>\n"
		+ " &nbsp;\n"
		+ "   ftp.ncd.com:/pub/ncd/technology/src/nas\n"
		+ "   ftp.x.org:/contrib/audio/nas\n"
		+ "</pre>"
		+ "<p>Release 1.2 of NAS is also included with the X11R6"
		+ "contrib distribution."
		+ "<p>After installing NAS, you will then need to reconfigure Qt with NAS sound support");
    }

    TQPopupMenu file = new TQPopupMenu(this);
    file.insertItem("Play &1",  this, TQ_SLOT("doPlay1()"), new TQKeySequence(CTRL+Key_1));
    file.insertItem("Play &2",  this, TQ_SLOT("doPlay2()"), new TQKeySequence(CTRL+Key_2));
    file.insertItem("Play from bucket &3",  this, TQ_SLOT("doPlay3()"), new TQKeySequence(CTRL+Key_3));
    file.insertItem("Play from bucket &4",  this, TQ_SLOT("doPlay4()"), new TQKeySequence(CTRL+Key_4));
    file.insertSeparator();
    file.insertItem("Play 3 and 4 together",  this, TQ_SLOT("doPlay34()"));
    file.insertItem("Play all together",  this, TQ_SLOT("doPlay1234()"));
    file.insertSeparator();
    file.insertItem("E&xit",  tqApp(), TQ_SLOT("quit()"));
    menuBar().insertItem("&File", file);
}

void doPlay1()
{
    TQSound.play("sounds/1.wav");
}

void doPlay2()
{
    TQSound.play("sounds/2.wav");
}

void doPlay3()
{
    bucket3.play();
}

void doPlay4()
{
    bucket4.play();
}

void doPlay34()
{
    // Some sound platforms will only play one sound at a time
    bucket3.play();
    bucket4.play();
}

void doPlay1234()
{
    // Some sound platforms will only play one sound at a time
    TQSound.play("sounds/1.wav");
    TQSound.play("sounds/2.wav");
    bucket3.play();
    bucket4.play();
}

public static void main(String[] args)
{
    TQApplication app = new TQApplication(args);
    SoundPlayer sp = new SoundPlayer();
    app.setMainWidget(sp);
    sp.setCaption("Qt Example - Sounds");
    sp.show();
    app.exec();
    return;
}

	static {
		qtjava.initialize();
	}

}