U++ framework
Do not panic. Ask here before giving up.

Home » Developing U++ » U++ Developers corner » Sound in linux (Lack of standards in Linux is a problem but there are some near-standards)
Re: Sound in linux [message #44096 is a reply to message #44094] Wed, 24 December 2014 13:18 Go to previous messageGo to previous message
Klugier is currently offline  Klugier
Messages: 1117
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Mirek,

The detection can be done in following way:
// Copy from PrinterJob.cpp -> I think it should be part of POSIX U++ library!!!
static String System(const char *cmd, const String& in)
{
	String ofn = GetTempFileName();
	String ifn = GetTempFileName();
	SaveFile(ifn, in);
	String c = cmd;
	c << " >" << ofn;
	if(in.GetCount())
		c << " <" << ifn;
	String q;
	if(system(c) >= 0)
		q = LoadFile(ofn);
	FileDelete(ofn);
	FileDelete(ifn);
	return q;
}

static String FindPlayer()
{
	static String player;
	
	if (player.IsEmpty()) {
		const char *players[] = { "play", "ogg123" }; // <- Add all possible players here!!!
		
		for (int i = 0; i < __countof(players); i++) {
			if (!System("which " + String(players[i]), Null).IsEmpty()) {
				player = players[i];
				break;
			}
		}
	}
	
	return player;
}

static void LinuxBeep(const char *name)
{
	String player = FindPlayer();
	if (!player.IsEmpty()) {
		String fn = "/usr/share/sounds/" + CurrentSoundTheme + "/stereo/dialog-" + name;
		system(player + " -q " + fn + (FileExists(fn + ".ogg") ? ".ogg" :
        	                           FileExists(fn + ".oga") ? ".oga" :
        	                           FileExists(fn + ".wav") ? ".wav" :
        	                           ".*")
	    	   + " >/dev/null 2>/dev/null&");
	}
}


IMO, There is a problem that function "System" is not part of U++ (I don't want to do copy&past). Can we do something with that issue?

Sincerely,
Klugier
  • Attachment: Sound.diff
    (Size: 1.79KB, Downloaded 363 times)


U++ - one framework to rule them all.

[Updated on: Wed, 24 December 2014 13:21]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Raster::Line segfaults ... sometimes.
Next Topic: Adding network proxy support to U++
Goto Forum:
  


Current Time: Tue May 19 13:18:30 GMT+2 2026

Total time taken to generate the page: 0.00837 seconds